通过使用Android新的Android应用程序包我发现我的两个谷歌游戏商店应用程序中找不到资源崩溃: -
以下是来自其中一个应用的结构的堆栈跟踪: -
Unable to start activity ComponentInfo{/com.Lastyear.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_item_background_holo_dark.xml from drawable resource ID #0x7f08002c
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5363)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(NativeStart.java)
build.gradle依赖项: -
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.support:palette-v7:27.1.1'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.android.support:design:27.1.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.github.hotchemi:android-rate:1.0.1'
implementation 'com.hannesdorfmann.smoothprogressbar:library:1.0.0'
implementation 'com.android.support:palette-v7:27.1.1'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.muddzdev:styleabletoast:1.0.9'
implementation 'com.github.GrenderG:Toasty:1.2.5'
implementation 'com.hannesdorfmann.smoothprogressbar:library:1.0.0'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.github.medyo:fancybuttons:1.8.4'
implementation 'com.irozon.sneaker:sneaker:1.0.1'
implementation 'com.sdsmdg.tastytoast:tastytoast:0.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
implementation 'petrov.kristiyan:colorpicker-library:1.1.8'}
仅在Android 4操作系统上发生了一件事,而不是新版本的Android。我发现其他应用程序在使用Android应用程序包之前存在相同的资源未找到问题。库或代码中是否存在问题,或者是因为Android应用程序包的测试版?
我认为这个问题也与此有关: - Error inflating class android.support.design.widget.NavigationView after adding SwitchCompat in Android App Bundle
答案 0 :(得分:22)
这几乎可以肯定是用户通过P2P共享程序共享(旁载)应用程序,或者将APK上传到网络上,然后其他用户从网络上下载和安装。
过去用于处理非Android App Bundle应用程序的人们只是传输和共享主要APK。但是您的App Bundle应用程序具有很多“拆分APK”,用于存储资源之类的东西,这就是节省大小的方式。您可以阅读有关此过程on the help page的所有信息。如果用户在未安装正确的拆分APK的情况下安装主APK,则在应用首次尝试加载资源时会发生“找不到资源”崩溃。
如果您想支持用户仅加载主应用程序和主APK,可以尝试检测到这种情况并向用户显示一条消息(不使用任何资源),并显示“请从Google Play安装”。或者,您可以决定不支持以这种方式共享APK的用户。
我怀疑从长远来看,网站和P2P共享程序会更好地正确共享此类APK,因此我不会花太多时间为此担心。
如果您发现较低版本的Android上发生这种情况的频率更高,则可能不是由于较低版本的Android上的错误所致。相反,这可能是因为在用户通常使用P2P共享应用程序的国家(例如印度),用户使用旧版本电话的可能性也更大。
答案 1 :(得分:9)
问题可能是您的应用已经侧载,即未通过Play商店安装,并且已在这些设备上手动安装了不兼容的APK。
答案 2 :(得分:3)
由于仅在迁移到Android App Bundle后才在Android 4设备上发生这种情况,因此我在添加以下内容后发现了一种解决方法:-
public class App extends Application {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); }
在build.gradle中:-
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
如本文所述: Using android vector Drawables on pre Lollipop crash
这在所有Android版本上都在发生。我在Apk中加载了Apk并能够在logcat中重现相同的错误,因此只能通过从我的项目中删除SwitchCompat来解决此问题,我知道这是一个临时修复程序,Google一定会对此做一些事情,以便至少不会发生崩溃在侧面加载apk之后,也许重定向到Play商店将是更好的选择。但是,迁移到Android App Bundle后,应用程序崩溃肯定会影响应用程序的稳定性,因为许多用户会定期这样做。
答案 3 :(得分:3)
可接受的答案是绝对正确的-root of this issue是APK文件的侧面加载。
尽管如此,许多人仍在寻找解决方法,询问如何正确处理此案。
在我的应用中,我执行了以下操作:
创建名为pixel.png
的1x1图像,并将其放置到以下所有文件夹中:drawable-mdpi
,drawable-hdpi
,drawable-xhdpi
,drawable-xxhdpi
,{ {1}}。
创建简单的drawable-xxxhdpi
,其中显示了静态消息,例如
此应用程序副本已损坏,无法启动。
请从Google Play安装原始版本
然后只需从包装在Activity
子句中的getDrawable(R.drawable.pixel)
中调用Activity.onCreate()
。
如果捕获到异常,则只需完成当前try/catch
并从步骤#2开始另一个。
完成!
此解决方案效果很好,现在我什至从Firebase Analytics获得数据也证实了这一点。
从46k新用户(事件Activity
)中,有266个用户遇到了此错误(已捕获),有221个用户单击了导致Google Play的按钮。
这是我的源代码(on GitHub也可用):
DrawablesValidator.java
first_open
答案 4 :(得分:2)
有点晚了,但是Google为Sideloading crash prevention
引入了新的API,通过它可以检测使用Android应用程序捆绑包构建的应用程序安装不完整。
例如,考虑使用Android应用程序捆绑包进行优化的应用程序 使用拆分APK的应用下载大小。用户从以下位置下载应用程序时 Google Play商店,它可以确保设备下载并 安装运行该应用程序所需的完整拆分APK的完整集合 该特定设备。当您绕过Google Play来加载 应用程序,平台没有足够的数据来验证应用程序 安装,并不能保证该应用程序的正常功能。
首先在您的项目中包含1.6.0或更高版本的Play Core库。
在您的应用项目的build.gradle文件中添加以下内容:
buildscript {
dependencies {
...
// Use bundletool 0.9.0 or higher when building with the
// Android Gradle plugin.
classpath 'com.android.tools.build:bundletool:0.9.0'
}
}
您可以使用以下3种方法之一
1)通过清单注册支票
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication" >
<application
...
android:name="com.google.android.play.core.missingsplits.MissingSplitsDetectingApplication" >
</application>
...
</manifest>
2)在自定义Application类中应用检查
public class MyCustomApplication extends Application {
@Override
public void onCreate() {
if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
// Skip app initialization.
return;
}
super.onCreate();
...
}
}
3)将检查应用于内容提供商
public class ExampleProvider extends ContentProvider {
@Override
public boolean onCreate() {
if (MissingSplitsManagerFactory.create(getContext()).isMissingRequiredSplits()) {
// Skip provider initialization.
return false;
}
super.onCreate();
...
}
}
了解更多:https://developer.android.com/reference/com/google/android/play/core/release-notes?hl=en-419#1-6-0
答案 5 :(得分:1)
对于内部测试,我们无法侧面加载aab文件apks。只有两种方式可以在发布到生产环境之前为用户提供apk。
1)我们必须给出Universal.apk文件检查的目的
java -jar bundletool-all-0.12.0.jar build-apks --bundle =(构建路径)debug.aab --output =(输出路径)debug.apks --mode = universal
2)我们必须将aab文件上传到Playstore,然后在一切正常的情况下首先发布以进行内部测试,然后发布其正式版。
答案 6 :(得分:0)
从上面的链接中,我了解到应用程序中使用的图标应位于可绘制资源文件夹中,而启动图标应位于mipmap资源文件夹中。我转移了我的图标,它对我有用。
答案 7 :(得分:0)
您可以从play console检查用户共享(侧面加载)应用程序 登录Play控制台,选择要在其上发布应用包而不是apk的应用。
选择 Android Vital-> ANR和崩溃,然后点击崩溃标签。
选择从播放安装
答案 8 :(得分:0)
我遇到了同样的问题,我的应用程序崩溃了,无法从资源中找到字体和音频文件。问题是我将Gradle-wrapper.properties中的Gradle URL从4.10.1更新为5.6.4,但没有更新库。当我恢复到4.10.1时,它开始正常工作。