Androidstudio2.3.1編譯生成的APK檔案直接拿來安裝時崩潰以及臨時解決辦法
今天做完小專案之後,想把apk檔案通過QQ發給別人試試,按照平常在app\build\outputs\apk目錄下就可以找到,結果將apk拿給別人安裝的時候發現崩潰,,之前除錯的時候一直用手機連線電腦直接執行,沒有出現錯誤:
Androidstudio的Log出現錯誤資訊如下,提示是找不到一個Activity,很顯然是不可能的,剛才還在手機執行,然後發現apk檔案比我在手機安裝的要小,所以就應該是這個apk檔案不夠完整,具體原因不太清楚(試了平常的專案,也是這樣,網上沒找到原因跟解決辦法),突然想起來之前沒帶資料線的時候都是通過CMD命令列進行編譯的,那時候直接在資料夾裡面拿到apk檔案直接安裝是不會出錯的,按照這種方法試了一下果然APK檔案大小比剛才明顯變大,可以正常安裝執行沒問題!!!!
-------------------------------------------
解決辦法:直接BuildAPK就行了
-------------------------------------------
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.administrator.product/com.example.administrator.product.ProductActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.administrator.product.ProductActivity" on path: DexPathList[[zip file "/data/app/com.example.administrator.product-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.administrator.product-1/lib/arm64, /system/lib64, /vendor/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2722)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6114)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.administrator.product.ProductActivity" on path: DexPathList[[zip file "/data/app/com.example.administrator.product-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.administrator.gecenproduct-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2553)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2722)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6114)