web-dev-qa-db-ja.com

バイナリXMLファイルの行#1:無効なドロウアブルタグベクトル

ほとんどのデバイスで完璧に動作するアプリがあります。ただし、API <21のデバイスでアプリケーションを実行しようとすると、致命的な例外が発生します。

ログは次のとおりです。

Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aceinteract.sleak/com.aceinteract.sleak.activity.LoginRegisterActivity}: Android.view.InflateException: Binary XML file line #9: Error inflating class EditText
at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2262)
at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2316)
at Android.app.ActivityThread.access$700(ActivityThread.Java:158)
at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1296)
at Android.os.Handler.dispatchMessage(Handler.Java:99)
at Android.os.Looper.loop(Looper.Java:176)
at Android.app.ActivityThread.main(ActivityThread.Java:5365)
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:1102)
at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: Android.view.InflateException: Binary XML file line #9: Error inflating class EditText
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:710)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:752)
at Android.view.LayoutInflater.parseInclude(LayoutInflater.Java:846)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:742)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:495)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.Java:60)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:397)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:353)
at Android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.Java:287)
at Android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.Java:139)
at com.aceinteract.sleak.activity.LoginRegisterActivity.onCreate(LoginRegisterActivity.kt:21)
at Android.app.Activity.performCreate(Activity.Java:5326)
at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1097)
at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2225)
at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2316) 
at Android.app.ActivityThread.access$700(ActivityThread.Java:158) 
at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1296) 
at Android.os.Handler.dispatchMessage(Handler.Java:99) 
at Android.os.Looper.loop(Looper.Java:176) 
at Android.app.ActivityThread.main(ActivityThread.Java:5365) 
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:1102) 
at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:869) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: Android.content.res.Resources$NotFoundException: File res/drawable/ic_person_accent_24dp.xml from drawable resource ID #0x7f07006f
at Android.content.res.Resources.loadDrawable(Resources.Java:2842)
at Android.content.res.TypedArray.getDrawable(TypedArray.Java:602)
at Android.widget.TextView.<init>(TextView.Java:1023)
at Android.widget.EditText.<init>(EditText.Java:76)
at Android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.Java:64)
at Android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.Java:60)
at Android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.Java:112)
at Android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.Java:1016)
at Android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.Java:1073)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.Java:280)
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:681)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:752) 
at Android.view.LayoutInflater.parseInclude(LayoutInflater.Java:846) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:742) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:495) 
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.Java:60) 
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:397) 
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:353) 
at Android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.Java:287) 
at Android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.Java:139) 
at com.aceinteract.sleak.activity.LoginRegisterActivity.onCreate(LoginRegisterActivity.kt:21) 
at Android.app.Activity.performCreate(Activity.Java:5326) 
at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1097) 
at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2225) 
at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2316) 
at Android.app.ActivityThread.access$700(ActivityThread.Java:158) 
at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1296) 
at Android.os.Handler.dispatchMessage(Handler.Java:99) 
at Android.os.Looper.loop(Looper.Java:176) 
at Android.app.ActivityThread.main(ActivityThread.Java:5365) 
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:1102)at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:869) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at Android.graphics.drawable.Drawable.createFromXmlInner(Drawable.Java:917)
at Android.graphics.drawable.Drawable.createFromXml(Drawable.Java:858)
at Android.content.res.Resources.loadDrawable(Resources.Java:2839)
at Android.content.res.TypedArray.getDrawable(TypedArray.Java:602) 
at Android.widget.TextView.<init>(TextView.Java:1023) 
at Android.widget.EditText.<init>(EditText.Java:76) 
at Android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.Java:64) 
at Android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.Java:60) 
at Android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.Java:112) 
at Android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.Java:1016) 
at Android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.Java:1073) 
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.Java:280) 
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:681) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:752) 
at Android.view.LayoutInflater.parseInclude(LayoutInflater.Java:846) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:742) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:760) 
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:495) 
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.Java:60) 
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:397) 
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:353) 
at Android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.Java:287) 
at Android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.Java:139) 
at com.aceinteract.sleak.activity.LoginRegisterActivity.onCreate(LoginRegisterActivity.kt:21) 
at Android.app.Activity.performCreate(Activity.Java:5326) 
at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1097) 
at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2225) 
at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2316) 
at Android.app.ActivityThread.access$700(ActivityThread.Java:158) 
at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1296) 
at Android.os.Handler.dispatchMessage(Handler.Java:99) 
at Android.os.Looper.loop(Looper.Java:176) 
at Android.app.ActivityThread.main(ActivityThread.Java:5365) 
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:1102) 
at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:869) 
at dalvik.system.NativeStart.main(Native Method) 

レイアウトXML

<?xml version="1.0" encoding="utf-8"?>
<Android.support.constraint.ConstraintLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:layout_width="match_parent"
    Android:layout_height="wrap_content"
    Android:id="@+id/layout_register"
    Android:visibility="gone"
    xmlns:app="http://schemas.Android.com/apk/res-auto">

    <EditText
        Android:id="@+id/edit_register_full_name"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        Android:drawableEnd="@drawable/ic_person_accent_24dp"
        Android:padding="20dp"
        Android:layout_width="0dp"
        Android:hint="@string/hint_full_name"
        Android:singleLine="true"
        Android:layout_height="wrap_content"
        Android:inputType="textPersonName"
        Android:drawableRight="@drawable/ic_person_accent_24dp" />

    <EditText
        Android:id="@+id/edit_register_email"
        app:layout_constraintTop_toBottomOf="@id/edit_register_full_name"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        Android:drawableEnd="@drawable/ic_email_accent_24dp"
        Android:padding="20dp"
        Android:layout_width="0dp"
        Android:hint="@string/hint_email"
        Android:inputType="textEmailAddress"
        Android:layout_height="wrap_content"
        Android:drawableRight="@drawable/ic_email_accent_24dp" />

    <EditText
        Android:id="@+id/edit_register_password"
        app:layout_constraintTop_toBottomOf="@id/edit_register_email"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        Android:drawableEnd="@drawable/ic_vpn_key_accent_24dp"
        Android:padding="20dp"
        Android:inputType="textPassword"
        Android:layout_width="0dp"
        Android:hint="@string/hint_password"
        Android:layout_height="wrap_content"
        Android:drawableRight="@drawable/ic_vpn_key_accent_24dp" />

    <CheckBox
        Android:id="@+id/check_register_show_password"
        Android:text="@string/desc_show_password"
        Android:layout_marginTop="10dp"
        app:layout_constraintTop_toBottomOf="@id/edit_register_password"
        app:layout_constraintLeft_toLeftOf="parent"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content" />

</Android.support.constraint.ConstraintLayout>

gradleファイル:

apply plugin: 'com.Android.application'

apply plugin: 'kotlin-Android'

apply plugin: 'kotlin-Android-extensions'

Android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.aceinteract.sleak"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "Android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-Android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '27.0.2'
}

androidExtensions {
    experimental = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.Android.support:appcompat-v7:27.0.2'
    implementation 'com.Android.support:design:27.0.2'
    implementation 'com.Android.support:customtabs:27.0.2'
    implementation 'com.Android.support:support-vector-drawable:27.0.2'
    implementation 'com.Android.support:support-v4:27.0.2'
    implementation 'com.Android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.Android.support:animated-vector-drawable:27.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.Android.support.test:runner:1.0.1'
    androidTestImplementation 'com.Android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.Android.support:cardview-v7:27.0.2'
    implementation 'com.Android.support:gridlayout-v7:27.0.2'
    implementation 'com.Android.support:recyclerview-v7:27.0.2'
    implementation 'com.Android.support:design:27.0.2'
    implementation 'com.Android.support:palette-v7:27.0.2'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.mikhaellopez:circularimageview:3.0.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
}

AppComaptEditTextに変更しようとしましたが、それでも同じエラーが発生します。

前もって感謝します :)

17
Ace Falobi

ドキュメント aboutVector Graphics言います:

Android 4.4(APIレベル20)以前では、ベクトルドロアブルはサポートされていません。

Support Libraryを使用すると、属性app:srcCompatを使用した下位互換性がありますが、Android:drawableRightに対してバックポートされません。

解決策は、これらの場合に.PNGファイルを使用し続けるか、コードで設定することです。

30
Juan Cruz Soler

描画可能なベクターを作成するには:

_vector = VectorDrawableCompat.create(context.getResources(), R.drawable.res, null);
_

またはAppCompatDelegate.setCompatVectorFromResourcesEnabled(true)をApplication onCreate()メソッドに追加します

2
Mikhail Sharin