Эта проблема возникает после интеграции Dagger 2 для реализации внедрения зависимостей библиотеки ImageDownloader при запуске приложения.
Это то, что я сделал:
В build.gradle.Я добавил эти строки:
implementation "com.google.dagger:dagger:2.16"
implementation "com.google.dagger:dagger-android-support:2.16"
annotationProcessor "com.google.dagger:dagger-compiler:2.16"
annotationProcessor "com.google.dagger:dagger-android-processor:2.16"
Это мой класс API, в котором я хотел отделить зависимости от класса активности:
public class ImageDownloaderApi {
@Inject
public ImageDownloaderApi(){
}
//some other methods here
}
В своем MainActivity
я добавил эти строки:
public class MainActivity extends Activity {
@Inject
ImageDownloaderApi imageDownloaderApi;
@Override
protected void onCreate(Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Затем создал объект Application
:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
}
}
Затем зарегистрировал класс Application
через манифест следующим образом:
<application
android:name=".MyApplication"
Я создалмодуль с именем MyApplicationModule
, например:
@Module
public abstract class MyApplicationModule {
@ContributesAndroidInjector
abstract MainActivity contributeActivityInjector();
}
Я создал интерфейс с именем MyApplicationComponent
:
@Component(modules = { AndroidInjectionModule.class, MyApplicationModule.class})
public interface MyApplicationComponent extends AndroidInjector<MyApplication> {
}
MyApplication
class:
public class MyApplication extends Application implements HasActivityInjector {
@Inject
DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;
@Override
public void onCreate() {
super.onCreate();
DaggerMyApplicationComponent.create().inject(this);
}
@Override
public DispatchingAndroidInjector<Activity> activityInjector() {
return dispatchingAndroidInjector;
}
}
Теперь после этой реализации, когда я запускаю приложение в эмуляторе, приложение вылетает со следующими журналами:
--------- beginning of crash
11-20 14:51:03.201 6745-6745/com.my.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.my.app, PID: 6745
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/ImmutableMap;
at com.my.app.di.DaggerMyApplicationComponent.getMapOfClassOfAndProviderOfFactoryOf(DaggerMyApplicationComponent.java:36)
at com.my.app.di.DaggerMyApplicationComponent.getDispatchingAndroidInjectorOfActivity(DaggerMyApplicationComponent.java:42)
at com.my.app.di.DaggerMyApplicationComponent.injectMyApplication(DaggerMyApplicationComponent.java:68)
at com.my.app.di.DaggerMyApplicationComponent.inject(DaggerMyApplicationComponent.java:62)
at com.my.app.di.DaggerMyApplicationComponent.inject(DaggerMyApplicationComponent.java:16)
at com.my.app.di.MyApplication.onCreate(MyApplication.java:19)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.collect.ImmutableMap" on path: DexPathList[[zip file "/data/app/com.my.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app-1/lib/x86, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.my.app.di.DaggerMyApplicationComponent.getMapOfClassOfAndProviderOfFactoryOf(DaggerMyApplicationComponent.java:36)
at com.my.app.di.DaggerMyApplicationComponent.getDispatchingAndroidInjectorOfActivity(DaggerMyApplicationComponent.java:42)
at com.my.app.di.DaggerMyApplicationComponent.injectMyApplication(DaggerMyApplicationComponent.java:68)
at com.my.app.di.DaggerMyApplicationComponent.inject(DaggerMyApplicationComponent.java:62)
at com.my.app.di.DaggerMyApplicationComponent.inject(DaggerMyApplicationComponent.java:16)
at com.my.app.di.MyApplication.onCreate(MyApplication.java:19)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 18 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Для получения дополнительной информации.Я также получаю эту строку предупреждения перед журналами, которые я разместил выше
11-20 14:51:03.172 6745-6745/? E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system