23

Android Studio 3 RC1我的应用在更新到(Gradle4,AndroidGradle插件 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 Studio2 上)。在github上也有描述,但没有答案。

4

4 回答 4

27

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


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

它会工作的。图书馆有问题。

于 2017-10-26T09:02:24.447 回答
7

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'我的项目使用 android gradle 插件 3.0 和 compileSdk 27​​。我无法使用此线程中建议的解决方案 ( ) 使其与此设置一起使用。

它抱怨ViewPager#removeOnPageChangeListener在支持库的第 24 版中添加了诸如不存在之类的方法。我认为这与该库直接包含 android-support-v4.jar 的事实有关。

我不想浏览我所有的 xml 文件并以编程方式设置属性,所以我最终创建了一个使用 gradle 构建库并将 compileSdk/minSdk/support-v4 提升到更现代版本的 fork。

你可以在这里找到项目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 个分叉的海洋中肯定有另一个项目可以做到这一点,但我不知道如何找到它。)

于 2017-12-13T05:11:38.037 回答
6

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'使用jitpack.ioandroid gradle 插件 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);
于 2017-11-07T16:38:18.030 回答
5

我找到了jitpack.io最简单的方法:

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

接着:

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

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

于 2017-12-03T18:08:22.737 回答