我的Android Studio应用仅适用于API 23及更高版本

问题描述 投票:1回答:2

我需要为API min sdk版本16构建一个应用程序,它构建成功,但它拒绝为23以下的API工作。消息显示“不幸的是,AppName已经停止”,但对于API 23及更高版本非常有效

我在模拟器API 16中运行应用程序时遇到的logcat错误

12-20 13:55:27.942    2612-2612/com.rhmfx.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rhmfx.myapplication/com.rhmfx.myapplication.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_vector_test.xml from drawable resource ID #0x7f020052
            at android.content.res.Resources.loadDrawable(Resources.java:1923)
            at android.content.res.Resources.getDrawable(Resources.java:659)
            at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:355)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:189)
            at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:710)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194)
            at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
            at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:129)
            at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:152)
            at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
            at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:204)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:184)
            at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:518)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70)
            at com.rhmfx.myapplication.MainActivity.onCreate(MainActivity.java:36)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
            at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
            at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
            at android.content.res.Resources.loadDrawable(Resources.java:1920)
            at android.content.res.Resources.getDrawable(Resources.java:659)
            at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:355)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:201)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:189)
            at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:710)
            at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:194)
            at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
            at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:129)
            at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:152)
            at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:29)
            at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:53)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:204)
            at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:184)
            at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:518)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:70)
            at com.rhmfx.myapplication.MainActivity.onCreate(MainActivity.java:36)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

在我的build.gradle文件中,设置是

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.1'

    defaultConfig {
        applicationId "com.rhmfx.myapplication"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}

请帮我修复显示的错误,以便我可以运行API 16及更高版本的应用程序。谢谢

android api android-studio sdk
2个回答
0
投票

具有最高Api级别的第三方库可能会导致此错误。请看这个问题。

My target SDK version is 25 but Google Play says app only supports 4.1-4.4 devices?


0
投票

主要问题是:

引起:org.xmlpull.v1.XmlPullParserException:二进制XML文件行17:无效的可绘制标记向量

您必须指定矢量drawables支持:

 vectorDrawables.useSupportLibrary = true  

添加到您的build.gradle文件,defaultConfig部分:

defaultConfig {
        applicationId "com.rhmfx.myapplication"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true  
    }
© www.soinside.com 2019 - 2024. All rights reserved.