FAQ: Android app 編譯好后安裝到手機,運行時閃退,報如下錯誤:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{io.grpc.helloworldexample/io.grpc.helloworldexample.HelloworldActivity}: java.lang.ClassNotFoundException: Didn't find class "io.grpc.helloworldexample.HelloworldActivity" on path: DexPathList[[zip file "/data/app/io.grpc.helloworldexample-aHJfGmXKi-KoAnqDIRZHhQ==/base.apk"],nativeLibraryDirectories=[/data/app/io.grpc.helloworldexample-aHJfGmXKi-KoAnqDIRZHhQ==/lib/arm64, /system/lib64, /vendor/lib64]]
問題原因:
重復拷貝工程,並且重名工程都在as中打開過,導致as產生混淆,找不到相應類:
解決辦法:
直接禁用Instant run, 這個效果最直接
disable Instant Run Go to File -> Settings -> Build,Execution, Deployment -> Instant Run -> Uncheck the checkbox for instant run. Run your app once and this apk file work properly..
試了下下面其他的辦法,對GRPC上的這個問題解決沒有效果,只能禁用即時編譯,看來這個即時編譯就是一個擺設,不實用,毛病問題太多!!!
其他的解決辦法(供參考):
DELETE THAT FOLDER .gradle.
deleted "build" folder under "app" folder.
Change the application name in AndroidManifest to full path
Clean Project
Rebuild Project
Build APK
My problem solved using use multi dex:
android {
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies
{
compile 'com.android.support:multidex:1.0.0'
}
// in AndroidManifest.xml:
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
public class MyApplication extends MultiDexApplication
Make sure this Diable preDexLibraries
In your app module .gradle file
android {
dexOptions {
preDexLibraries false
}
}
