gradle 不支持的操作异常:无法将索引为5的值转换为颜色:类型=0x5

tyu7yeag  于 2023-04-12  发布在  其他
关注(0)|答案(5)|浏览(131)

我的应用程序在更新到Android Studio 3 RC1Gradle 4,Android Gradle插件3 RC2)后崩溃。

This is the error I am having:
java.lang.RuntimeException: Unable to start activity ComponentInfo{*****}:
android.view.InflateException: Binary XML file line #0: Binary XML file line #0:
Error inflating class com.viewpagerindicator.CirclePageIndicator
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.viewpagerindicator.CirclePageIndicator
    Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.viewpagerindicator.CirclePageIndicator
    Caused by: java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.newInstance0(Native Method)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
       at android.view.LayoutInflater.createView(LayoutInflater.java:647)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal(CalligraphyLayoutInflater.java:211)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000(CalligraphyLayoutInflater.java:20)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:302)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
       at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
       at com.raimbekov.android.sajde.zikr.ZikrActivity.onCreate(ZikrActivity.java:195)
       at android.app.Activity.performCreate(Activity.java:6975)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 5 to color: type=0x5
    10-20 10:48:09.562 6156-6156 E/AndroidRuntime:     at android.content.res.TypedArray.getColor(TypedArray.java:473)
        at com.viewpagerindicator.CirclePageIndicator.<init>(CirclePageIndicator.java:96)
        at com.viewpagerindicator.CirclePageIndicator.<init>(CirclePageIndicator.java:72)
            ... 34 more

我在更新之前没有这个问题(在Android Studio 2上)。在github上也有描述,但没有答案。

7cjasjjr

7cjasjjr1#

变更
compile 'com.viewpagerindicator:library:2.4.1@aar'

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
会有用的。图书馆出了点问题。

cotxawn7

cotxawn72#

我的项目使用android gradle plugin 3.0和compileSdk 27。我无法使用此线程中建议的解决方案(compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1')使其与此设置一起工作。
它抱怨像ViewPager#removeOnPageChangeListener这样的方法不存在,而这些方法已经添加到了支持库的第24版中。我认为这与库中直接包含android-support-v4.jar的事实有关。
我不想遍历所有的xml文件并以编程方式设置属性,所以我最终创建了一个使用gradle构建库的fork,并将compileSdk/minSdk/support-v4升级到更现代的版本。
您可以在这里找到项目https://github.com/splatte/ViewPagerIndicator
要在你的项目中使用它,从jitpack中获取它,如下所示:

allprojects {
    repositories {
      maven { url "https://jitpack.io" }
    }
}

然后:

dependencies {
    implementation 'com.github.splatte:ViewPagerIndicator:3.0.0'
}

(在ViewPagerIndicator拥有的4.300分叉的海洋中,一定有另一个项目可以做到这一点,但我不知道如何找到它。

4bbkushb

4bbkushb3#

使用jitpack.iocompile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'在android gradle plugin 3.0中不适用。
相反,我必须以编程方式设置所有视图属性,这些属性是我以前在xml布局中使用cpi:(或app:)属性设置的。
示例

<com.viewpagerindicator.CirclePageIndicator
    cpi:fillColor="@color/azure"
    cpi:pageColor="@color/white"
    cpi:radius="4dp"
    cpi:snap="true"
    cpi:strokeWidth="0dp" />

我删除了所有cpi:属性,并以编程方式设置它们:

circlePageIndicator.setFillColor(ContextCompat.getColor(getContext(), R.color.azure));
circlePageIndicator.setPageColor(ContextCompat.getColor(getContext(), R.color.white));
circlePageIndicator.setRadius((int) (4 * Resources.getSystem().getDisplayMetrics().density));
circlePageIndicator.setSnap(true);
circlePageIndicator.setStrokeWidth(0);
ctehm74n

ctehm74n4#

我发现jitpack.io是最简单的方法:

allprojects {
    repositories {
      maven { url "https://jitpack.io" }
    }
}

然后:

dependencies {
  implementation ('com.github.JakeWharton:ViewPagerIndicator:2.4.1'){
    exclude module: 'support-v4'
  }
}

需要注意的是,有两个版本的support-v4库破坏了它,直到我排除了其中一个。

hc2pp10m

hc2pp10m5#

好吧,这个库已经很长时间没有更新了,所以它目前在更新的sdk中产生了很多问题,因此您需要通过以下方式替换库

////旧库

implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'

//将其替换为下面的//用于View Pagerindicator

implementation 'com.github.splatte:ViewPagerIndicator:3.0.0'

它将工作,如果没有请不要忘记添加

maven { url "https://jitpack.io" }

//把它放在set.gradle里面

相关问题