在我的Android Studio项目中,我有几个模块,其中只有两个是应用程序模块(让我们称之为A和B),其他模块是库模块,有些模块由A和B使用.
对于模块A,启用multidex,而对于B,则不启用.
我遇到的问题是,当从一个配置(运行按钮旁边的下拉列表)切换,并运行另一个配置时,我总是会遇到一些错误.使其工作的唯一方法是完整的项目清洁.
当从A切换到B而没有干净时,我收到以下错误:
UNEXPECTED TOP-LEVEL EXCEPTION: java.util.zip.ZipException: error in opening zip file at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.(ZipFile.java:215) at java.util.zip.ZipFile. (ZipFile.java:145) at java.util.zip.ZipFile. (ZipFile.java:159) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:672) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311) at com.android.dx.command.dexer.Main.run(Main.java:277) at com.android.dx.command.dexer.Main.main(Main.java:245) at com.android.dx.command.Main.main(Main.java:106) 8 errors; aborting (all are similar to the one above, so I omitted them) Error:Execution failed for task ':Bapp'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
当从B切换到A时,A应用程序然后运行,但在运行时立即失败,说它无法在APK中找到我的自定义Application类:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kushtrim.mobile, PID: 3457 java.lang.RuntimeException: Unable to instantiate application com.kushtrim.application.MyAApplication: java.lang.ClassNotFoundException: Didn't find class "com.kushtrim.application.MyAApplication" on path: DexPathList[[zip file "/data/app/com.kushtrim.mobile-1/base.apk"],nativeLibraryDirectories=[/data/app/com.kushtrim.mobile-1/lib/x86, /data/app/com.kushtrim.mobile-1/base.apk!/lib/x86, /vendor/lib, /system/lib]] at android.app.LoadedApk.makeApplication(LoadedApk.java:578) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4680) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我指定了Multidex用法,因为我坚信这就是问题所在,因为如果我为两个项目打开它,就不会弹出错误,也不需要清理.
总而言之,有没有办法解决这个问题,以便可以避免干净的步骤?