2016-03-28 6 views
0

私はRoboActivityから派生したクラスといくつかの注入pojoフィールドを持つマルチモジュールプロジェクトを持っています。Roboguice throw ClassNotFoundException:AnnotationDatabaseImpl

これらのフィールドのクラスには、フィールドを注入したフィールドもあります。これらのクラスのいくつかは別々のモジュールに入っているので、私が必要とするのはモジュール間の相互注入です。

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

これらはモジュールでありますbuild.gradleファイル(スニペット):

build.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.androidapp" 
} 

build.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.androidapp.domain" 
} 

build.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.androidapp.persistence" 
} 

build.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" 
} 

AnnotationDatabaseImpl.classファイルは、ar.com.abimobileapps.androidapp、ar.com.abimobileapps.androidapp.domain、ar.com.abimobileapps.androidapp.persistenceおよびar.com.abimobileapps.platformパッケージに対して生成されます。ソースコードを調べると、注入されたすべての「注入する」クラスが参照されることがわかります。

だから、なぜ私は 'ClassNotFoundException:AnnotationDatabaseImpl'アプリケーションを実行すると理解できません。

正しく注入されたクラス(AboutActivityImpl、AboutPresenterImplおよびAppModule)は同じプロジェクトモジュールにあり、他の2つのクラス(失敗したクラス)は2つの異なるプロジェクトモジュール(1つのモジュールのAppInfo/DomainModule、AppInfoApi/PlatformModule他のモジュールで)。

Roboguiceはバージョン3.0.1です。

答えて

0

Roboguice.setUseAnnotationDatabases(false)を設定すると、例外を防ぐことができます。また、Roboguice 4.0への移行をお勧めします。 Roboguice 4.0は、GithubのRoboguiceプロジェクトのブランチrg-4-finalにあります。 Rg 4.0はより軽量なので、パフォーマンスははるかに優れています。

+0

'Roboguice.setUseAnnotationDatabases(false)'は、コンパイル時からランタイムリフレクションに切り替わるため、アプリケーションをたくさん遅くす​​る原因となります。 –

+0

私は知っていますが、試してみましたが、これはずっと前です。 RoboBlenderは動作しません。今は4.0を使用しています。 – Christine

+0

ええ私も、私は4.0でAnnotationDatabaseImplの問題がありました。私は 'apply plugin:com.neenbedankt.android-apt''が原因であることを知りました。 –