2

我对支持向量可绘制库有疑问。当我在预棒棒糖设备上测试我的应用程序时,应用程序崩溃了。我发现它是由使用矢量绘图引起的,我认为 support-vector-drawable 会解决它。不幸的是我不能让它工作。

我的应用程序 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "pl.testname"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'org.apmem.tools:layouts:1.10@aar'
    compile 'com.android.support:support-v4:23.2.1'
    compile 'com.android.support:support-vector-drawable:23.2.1'

    // androidannotations
    apt "org.androidannotations:androidannotations:4.0.0"
    compile "org.androidannotations:androidannotations-api:4.0.0"

    // retrofit
    compile 'com.squareup.retrofit2:retrofit:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0'
    compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
}

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    }
}

布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.MainActivity">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_menu_settings"/>

    (...)

</RelativeLayout>

v21\ic_menu_settings.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/>
</vector>

日志猫

    Process: pl.testname, PID: 309
  java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.testname/pl.testname.activities.MainActivity_}: android.view.InflateException: Binary XML file line #11: Error inflating class ImageView
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
      at android.app.ActivityThread.access$800(ActivityThread.java:135)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5001)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
      at dalvik.system.NativeStart.main(Native Method)
   Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class ImageView
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
      at pl.testname.fragments.ProductsFragment_.onCreateView(ProductsFragment_.java:58)
      at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
      at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602)
      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
      at android.app.Activity.performStart(Activity.java:5241)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
      at android.app.ActivityThread.access$800(ActivityThread.java:135) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5001) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
      at dalvik.system.NativeStart.main(Native Method) 
   Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02005b
      at android.content.res.Resources.getValue(Resources.java:1123)
      at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:285)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
      at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:49)
      at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:65)
      at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:53)
      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
      at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972)
      at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1031)
      at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
      at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
      at pl.testname.fragments.ProductsFragment_.onCreateView(ProductsFragment_.java:58) 
      at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) 
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) 
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) 
      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738) 
      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) 
      at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) 
      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602) 
      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) 
      at android.app.Activity.performStart(Activity.java:5241) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
      at android.app.ActivityThread.access$800(ActivityThread.java:135) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5001) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
      at dalvik.system.NativeStart.main(Native Method) 

使用带有 Gradle 2.1.0-alpha5 的 Android Studio 2.1 Preview 5。

有任何想法吗?

4

2 回答 2

2

重启android studio,你的问题就解决了......

如果它不能解决比将 ic_menu_settings.xml 文件放入可绘制文件夹中

于 2016-04-02T10:37:43.197 回答
1

更改位置对我有帮助:我在drawable-anydpi/中有我的矢量可绘制对象-这会导致崩溃-当我将可绘制对象移动到可绘制对象/时,它工作正常。

于 2018-02-16T09:37:22.483 回答