主要活动的ClassNotFoundException - Android Studio 0.8.2

时间:2014-07-13 19:23:06

标签: android android-studio

刚刚更新到Android Studio 0.8.2,当我的某个应用程序使用0.8.2构建时,我突然在启动主要活动时遇到ClassNotFoundException。

该应用程序处于版本控制(Git)中,因此我检查了旧版本,现在它们在执行时表现出相同的症状,并且在使用0.8.1构建时它们肯定正常工作。

我尝试过干净重建,动画同步,手动删除build /和.gradle / dirs,关闭&重新开放Android Studio等 - 我已经检查了我的项目的各种旧版本并在几台Android设备上测试了APK,这个问题在调试和发布版本中都是100%可重现的。

奇怪的是,虽然这个特定项目100%可重复,但我还有另一个正在建设和执行的项目。

我已经拆开了Android Player 0.8.2中使用apktool输出的APK,这个类肯定在那里。

$ pwd
/Users/ben/Development/go-android/Go/build/outputs/apk/Go-debug/smali/au/com/glassechidna/go/content
$ ls
AddTripFragment$1.smali             CreateTripFragment$OnQueryTextListener$1.smali  CreateTripFragment.smali            MainActivity.smali
AddTripFragment.smali               CreateTripFragment$OnQueryTextListener.smali    GoActivity.smali                TrainTimeFragment$1.smali
CreateTripActivity.smali            CreateTripFragment$OnSuggestionListener.smali   GoApplication.smali             TrainTimeFragment.smali
CreateTripFragment$1.smali          CreateTripFragment$StopCursor.smali     MainActivity$PagerAdapter.smali         TripFragment.smali

Stacktrace:https://gist.github.com/Benjamin-Dobell/a77bd8fffb03ddb37ff1

清单:https://gist.github.com/Benjamin-Dobell/ca7ee54d7562a0feab0c

Go / build.gradle [1]:https://gist.github.com/Benjamin-Dobell/f9a3a39d6f141e412dac

build.gradle [1]:https://gist.github.com/Benjamin-Dobell/2db744dd89e487325b65

MainActivity.java [2]:https://gist.github.com/Benjamin-Dobell/11a6335f56b6ababeeb4

有什么想法吗?

[1]取自最古老的提交之一,因为它具有较少的依赖性等等。但是,此提交的问题仍然可以100%重现。

[2]只是宣言。

1 个答案:

答案 0 :(得分:3)

从CLI清除似乎解决了这个问题。

向@yogurtearl道具,指出我正确的方向。

$ ./gradlew clean
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:Go:clean

BUILD SUCCESSFUL

Total time: 3.906 secs
$ ./gradlew assembleDebug
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:Go:preBuild
:Go:compileDebugNdk
:Go:preDebugBuild
:Go:checkDebugManifest
:Go:preReleaseBuild
:Go:prepareComAndroidSupportSupportV42000Library UP-TO-DATE
:Go:prepareDebugDependencies
:Go:compileDebugAidl
:Go:compileDebugRenderscript
:Go:generateDebugBuildConfig
:Go:generateDebugAssets UP-TO-DATE
:Go:mergeDebugAssets
:Go:generateDebugResValues UP-TO-DATE
:Go:generateDebugResources
:Go:mergeDebugResources
:Go:processDebugManifest
:Go:processDebugResources
:Go:generateDebugSources
:Go:compileDebugJava
:Go:preDexDebug
:Go:dexDebug
:Go:processDebugJavaRes UP-TO-DATE
:Go:validateDebugSigning
:Go:packageDebug
:Go:zipalignDebug
:Go:assembleDebug

BUILD SUCCESSFUL

Total time: 10.64 secs
$ adb uninstall au.com.glassechidna.go.debug
Success
$ adb install Go/build/outputs/apk/Go-debug.apk 
8553 KB/s (323343 bytes in 0.036s)
    pkg: /data/local/tmp/Go-debug.apk
Success

更新

自从运行上面的gradlew命令后,我现在可以在Android Studio中清理和构建。因此,似乎Android Studio没有正确清理,手动删除build /和.gradle /目录也不够。

现在,我只需要了解为什么这样做有效以及为什么在Android Studio中清理和构建没有...

如果你知道其他地方的任何其他州的gradle / gradlew商店可能是罪魁祸首,我很乐意通过评论来听到它。

更新2

我的Mac上一直存在这个问题。我注意到,当我在Android Studio中构建" preDexDebug"任务生成了几个警告如下:

objc[49452]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.

比较一个好的APK和一个坏的,我可以看到一些生成的DEX< d +类在两个APK之间变化很大。不幸的是,我还不知道问题的解决方案(我在CLI中使用Gradle Wrapper建立了工作)。