为什么我的应用程序无法在较旧的设备上运行?

时间:2019-01-29 08:23:15

标签: java android android-studio mobile-application

我的应用程序可以在Android Nougat和Oreo上正常运行,但是当我想以较低的版本(如棒棒糖)打开时无法运行。

我设置了minSdkVersion 15,尽管不起作用。

如果发现任何导致问题的原因,请让我。我在android应用程序开发中是一个新手,这就是为什么不了解这里出了什么问题。任何帮助深表感谢。预先感谢。

以下是我的build.gradle代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.internexia.app.gemsv1"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support:support-v4:28.0.0'
    compile 'com.android.support:design:28.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Logcat:

01-29 16:28:59.155 5887-5887/com.internexia.app.gemsv1 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.internexia.app.gemsv1, PID: 5887
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.internexia.app.gemsv1/com.internexia.app.gemsv1.HomeActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class ImageView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class ImageView
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.internexia.app.gemsv1.HomeActivity.onCreate(HomeActivity.java:40)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5254) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
     Caused by: android.content.res.Resources$NotFoundException: Resource "com.internexia.app.gemsv1:drawable/gems" (7f070065)  is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070065 a=-1 r=0x7f070065}
        at android.content.res.Resources.loadDrawableForCookie(Resources.java:2441)
        at android.content.res.Resources.loadDrawable(Resources.java:2381)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
        at android.widget.ImageView.<init>(ImageView.java:146)
        at android.widget.ImageView.<init>(ImageView.java:135)
        at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
        at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
        at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
        at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
        at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at com.internexia.app.gemsv1.HomeActivity.onCreate(HomeActivity.java:40) 
        at android.app.Activity.performCreate(Activity.java:5990) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5254) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
01-29 16:28:59.158 5887-5900/com.internexia.app.gemsv1 I/art: Background partial concurrent mark sweep GC freed 1597(218KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1057KB/2MB, paused 1.182ms total 139.996ms
01-29 16:33:59.849 5887-5887/com.internexia.app.gemsv1 I/Process: Sending signal. PID: 5887 SIG: 9

如果您知道这里有什么问题或其他建议,请帮助我。

2 个答案:

答案 0 :(得分:1)

将所有图像文件从drawable-v24文件夹传输到drawable文件夹。

如果您只是移动文件,错误将消失并且可以正常工作。

答案 1 :(得分:0)

似乎未完全支持某些SVG源。在活动的onCreate() 方法

中添加以下行:
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

并确保您在 XML文件中使用以下属性作为ImageView的属性: app:srcCompact而不是android:src来定义图像。