有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Roboguice抛出ClassNotFoundException:AnnotationDatabaseImpl

我有一个多模块项目,它有一个从RoboActivity派生的类,带有一些注入的pojo字段

这些字段的类也注入了字段,而这些字段反过来也注入了字段。其中一些类生活在不同的模块中,所以我需要的是跨模块注入

我按照Robo Blenders wiki(据说)中的说明操作,但在尝试运行应用程序时,我得到了“ClassNotFoundException:AnnotationDatabaseImpl”,应用程序停止了

以下是类(未显示接口):

@ContentView(R.layout.activity_about)
public class AboutActivityImpl extends AbstractActivityImpl implements AbstractActivity, AboutActivity {

    @InjectView(R.id.app_name) private TextView app_name;
    @InjectView(R.id.app_copyright) private TextView app_copyright;
    @InjectView(R.id.app_version) private TextView app_version;

    // MVP 
    @Inject
    AboutPresenter presenter;  //IS INJECTED

    // MVP 
    @Override
    protected MvpEvent setPresenter() {
        setPresenter(presenter);
        return new AboutActivityInitEvent();
    }
.
.
.
}

public class AboutPresenterImpl extends AbstractPresenterImpl implements AboutPresenter {
    @Inject
    AppInfo appInfo;  //IS INJECTED

    @SuppressWarnings("unused")
    @Inject @Config(Property.APP_COPYRIGHT) //IS INJECTED
    private String appCopyright;
.
.
.
}

public class AppInfoImpl implements AppInfo {
    @Inject
    AppInfoApi appInfoApi;  //IS NOT INJECTED!!

    public AppInfoImpl() {
    }
.
.
.
}

public class AppInfoApiImpl implements AppInfoApi {
    @Inject
    Application application;  //IS NOT INJECTED!!

    public AppInfoApiImpl() {
    }
.
.
.
}

Roboguice模块如下所示:

public class AppModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(AboutPresenter.class).to(AboutPresenterImpl.class);
    }
}

public class DomainModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(AppInfo.class).to(AppInfoImpl.class);
    }
}

public class PlatformModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(AppInfoApi.class).to(AppInfoApiImpl.class);
    }
}

清单如下:

    <manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
        package="ar.com.abimobileapps.安卓app">
        <application
            安卓:allowBackup="true"
            安卓:icon="@mipmap/ic_launcher"
            安卓:label="@string/app_name"
            安卓:supportsRtl="true"
            安卓:theme="@style/AppTheme">
            <meta-data 安卓:name="roboguice.modules"
                安卓:value="ar.com.abimobileapps.platform.config.PlatformModule,
ar.com.abimobileapps.安卓app.configuration.ConfigurationModule,
ar.com.abimobileapps.安卓app.persistence.config.PersistenceModule,
ar.com.abimobileapps.安卓app.domain.config.DomainModule,
ar.com.abimobileapps.安卓app.config.AppModule" />
            <meta-data 安卓:name="roboguice.annotations.packages"
                安卓:value="ar.com.abimobileapps.安卓app,
                               ar.com.abimobileapps.安卓app.domain,
                               ar.com.abimobileapps.安卓app.persistence,
                               ar.com.abimobileapps.platform" />
            <activity
                安卓:name=".ui.AboutActivityImpl">
                <intent-filter>
                    <action 安卓:name="安卓.intent.action.MAIN" />
                    <category 安卓:name="安卓.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    .
    .
    .
        </application>
    </manifest>

这些是构建的模块。gradle文件(片段):

建造。gradle(应用程序模块):

dependencies {
.
.
.
    // Roboguice
    compile 'org.roboguice:roboguice:3.0.1'
    provided 'org.roboguice:roboblender:3.0.1'
    // Modules
    compile project(':domain')
    compile project(':platform')
    compile project(':configuration')
}

project.tasks.withType(JavaCompile) { task ->
    options.compilerArgs << "-AguiceAnnotationDatabasePackageName=ar.com.abimobileapps.安卓app"
}

建造。gradle(域模块):

dependencies {
.
.
.
    // Roboguice
    compile 'org.roboguice:roboguice:3.0.1'
    provided 'org.roboguice:roboblender:3.0.1'
    // Modules
    compile project(':persistence')
    compile project(':platform')
}

project.tasks.withType(JavaCompile) { task ->
    options.compilerArgs << "-AguiceAnnotationDatabasePackageName=ar.com.abimobileapps.安卓app.domain"
}

建造。gradle(持久性模块):

dependencies {
.
.
.
    // Roboguice
    compile 'org.roboguice:roboguice:3.0.1'
    provided 'org.roboguice:roboblender:3.0.1'
}

project.tasks.withType(JavaCompile) { task ->
    options.compilerArgs << "-AguiceAnnotationDatabasePackageName=ar.com.abimobileapps.安卓app.persistence"
}

建造。gradle(平台模块):

dependencies {
.
.
.
    // Roboguice
    compile 'org.roboguice:roboguice:3.0.1'
    provided 'org.roboguice:roboblender:3.0.1'
}

project.tasks.withType(JavaCompile) { task ->
    options.compilerArgs << "-AguiceAnnotationDatabasePackageName=ar.com.abimobileapps.platform"
}

注释数据库impl。类文件是为包ar.com生成的。abimobileapps。安卓app,ar.com。abimobileapps。安德洛伊达普。域名,ar.com。abimobileapps。安德洛伊达普。持久性和ar.com。abimobileapps。站台检查其源代码时,我看到所有注入类和“to inject”类都被引用

因此,我无法理解为什么在运行应用程序时会出现“ClassNotFoundException:AnnotationDatabaseImpl”

正确注入的类(AboutActivityImpl、AboutPresentImpl和AppModule)位于同一个项目模块中,而其他两个类(失败的类)位于两个不同的项目模块中(一个模块中的AppInfo/DomainModule,另一个模块中的AppInfoApi/PlatformModule)

Roboguice是3.0.1版

知道吗


共 (1) 个答案

  1. # 1 楼答案

    您可以设置Roboguice.setUseAnnotationDatabases(false)以防止出现异常。另外,我建议您转到Roboguice 4.0。你可以在Github上的Roboguice项目中找到Roboguice 4.0作为分支rg-4-final。Rg 4.0更轻,因此性能更好