为什么Android Studio可以在真机上运行应用,安装失败? [英] Why can an app run in real device by Android Studio and failed by install?

查看:35
本文介绍了为什么Android Studio可以在真机上运行应用,安装失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Android Studio 的真实设备(Android 7.0 Table)上运行了一个应用,没问题.

I run an app in a real device (Android 7.0 Table) from Android Studio, it's OK.

现在我创建应用程序的 APK 文件,然后将其安装到我的真实设备上,完成我运行应用程序.

Now I create a APK file of the app, then I install it on my real device, finish I run the app.

我收到以下错误,为什么?

I get the following errors, why ?

为什么Android Studio可以在真机上运行应用,安装失败?

Why can an app run in real device by Android Studio and failed by install?

E:\>cd E:\Android_SDK\platform-tools

E:\Android_SDK\platform-tools>adb logcat --buffer=crash

03-20 12:05:29.378 15996 15996 E AndroidRuntime: FATAL EXCEPTION: main
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Process: info.dodata.voicerecorder, PID: 15996
03-20 12:05:29.378 15996 15996 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{info.dodata.voicerecorder/info.dodata.voicerecorder.ui.ActivityMain}: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class fragment
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2804)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2875)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.-wrap12(ActivityThread.java)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1578)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:105)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:156)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6617)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #25: Binary XML file line #25: Error inflating class fragment
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class fragment
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Caused by: java.lang.RuntimeException: Exception inflating info.dodata.voicerecorder:navigation/nav_graph line 66
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.q.r.c()
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at androidx.navigation.NavController.j(:2)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at androidx.navigation.fragment.NavHostFragment.L(:32)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.m.b.r.U(:19)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.m.b.p.onCreateView(:5)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.m.b.e.onCreateView(:4)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.b.c.n.v()
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.b.c.k.setContentView()
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at info.dodata.voicerecorder.ui.ActivityMain.onCreate(:2)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.Activity.performCreate(Activity.java:6910)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2757)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2875)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.-wrap12(ActivityThread.java)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1578)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:105)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:156)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6617)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: info.dodata.voicerecorder.model.MVoice
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.q.r.d(:1)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.q.r.b(:1)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at g.q.r.b(:27)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        ... 28 more
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: info.dodata.voicerecorder.model.MVoice
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.Class.classForName(Native Method)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.Class.forName(Class.java:400)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.Class.forName(Class.java:326)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        ... 31 more
03-20 12:05:29.378 15996 15996 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "info.dodata.voicerecorder.model.MVoice" on path: DexPathList[[zip file "/data/app/info.dodata.voicerecorder-1/base.apk"],nativeLibraryDirectories=[/data/app/info.dodata.voicerecorder-1/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
03-20 12:05:29.378 15996 15996 E AndroidRuntime:        ... 34 more

添加的内容

致阿明:谢谢!

我的应用在 Android Studio 中运行时可以正常运行.

My app can work well when I run it in Android Studio.

为了缩小文件大小,我在 Build.gradle 中使用了代码 A,但这可能会导致我在安装和运行单独的 apk 文件时未映像的错误.

In order to shrink file size, I use the Code A in my Build.gradle, but it maybe cause the error which I don't image when I install and run the alone apk file.

你的意思是我应该像 Code B 一样处理我的课程吗?太复杂了.

Do you mean I should handle my classes just like Code B? It's too complex.

顺便说一句,我认为minifyEnabled true"太可怕了,缩小后的apk文件只会导致运行时出错,我无法在Android Studio中进行测试.

BTW, I think "minifyEnabled true" is too terrible, the shrunk apk file only cause error in runtime, I can't test it in Android Studio.

代码 A

   Build.gradle
    
        buildTypes {
            release {
                minifyEnabled true
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        debug {
        }
    }

代码 B

-keep public class info.dodata.voicerecorder.model.** 
{
  public protected *;
}

推荐答案

我觉得 proguard/R8 已经删除了 info.dodata.voicerecorder.model.MVoice 类,因为我没有看到 .包名称中的调试后缀,我假设您正在安装启用了 minify 的发布变体.尝试使用以下方法保留模型类,或禁用 minify 以查明是否是原因

I feel like proguard/R8 had removed info.dodata.voicerecorder.model.MVoice class because I don't see a .debug postfix in the package name, I'm assuming that you're installing the release variant with minify enabled. Try to keep your model classes using following, or disable minify to find out if it's the cause or not

-keep public class info.dodata.voicerecorder.model.** 
{
  public protected *;
}

这篇关于为什么Android Studio可以在真机上运行应用,安装失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆