FAQ: Android app 編譯好後安裝到手機,運行時閃退,報以下錯誤:java
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]]android
問題緣由:app
重複拷貝工程,而且重名工程都在as中打開過,致使as產生混淆,找不到相應類:ide
解決辦法:gradle
直接禁用Instant run, 這個效果最直接ui
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..this
試了下下面其餘的辦法,對GRPC上的這個問題解決沒有效果,只能禁用即時編譯,看來這個即時編譯就是一個擺設,不實用,毛病問題太多!!! xml
其餘的解決辦法(供參考):ip
DELETE THAT FOLDER .gradle.ci
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
}
}