我有两个 APK。第一个 APK 是加载第二个 APK 的主 APK。在第二个 APK 中,我有下一个代码:
@Entity
public class RequestEntity {
@PrimaryKey
@NonNull
public String uid;
@ColumnInfo(name = "bucketName")
public String bucketName;
@ColumnInfo(name = "key")
public String key;
@ColumnInfo(name = "stream")
public byte[] stream;
@ColumnInfo(name = "metadata")
public byte[] metadata;
public RequestEntity(String bucketName, String key, byte[] stream, byte[] metadata) {
this.uid = bucketName + key;
this.bucketName = bucketName;
this.key = key;
this.stream = stream;
this.metadata = metadata;
}
}
@Dao
public interface RequestDao {
@Query("SELECT * FROM requestEntity")
List<RequestEntity> getAll();
@Query("SELECT * FROM requestEntity WHERE uid IN (:requestIds)")
List<RequestEntity> loadAllByIds(int[] requestIds);
@Insert
void insert(RequestEntity requestEntitie);
@Insert
void insertAll(RequestEntity... requestEntities);
@Delete
void delete(RequestEntity user);
}
@Database(entities = {RequestEntity.class}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
public abstract RequestDao requestDao();
}
我的问题是当我在第二个 APK 中调用此行时:
db = Room.databaseBuilder(context, AppDatabase.class, "database-name").build();
我得到例外:
java.lang.RuntimeException: cannot find implementation for [my package name].AppDatabase. AppDatabase_Impl does not exist
如果我将代码复制到主 APK 并从主 APK 调用此行,一切正常。