java.lang.NoClassDefFoundError : Failed resolution of: Landroid/support/v4/graphics/ColorUtils;

标签 java android android-support-library

java.lang.NoClassDefFoundErrorAndroid 5.1.1 中,但我在 6.0.1 上运行良好

这是有错误的类:

public class DuelsTextView extends AppCompatTextView {

    int fontType;

    public DuelsTextView(Context context) {
        super(context);
        init(null);
    }

    public DuelsTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public DuelsTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs);
    }

    public void init(AttributeSet attrs) {

        if (attrs != null) {
            TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DuelsTextView);
            fontType = a.getInteger(R.styleable.DuelsTextView_font_type, 0);
        }

        try {

            Typeface myTypeface = null;

            if (fontType == 0) {
                myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/BreeSerif-Regular.ttf");
            } else if (fontType == 1) {
                myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/MarkoOne-Regular.ttf");
            }

            this.setTypeface(myTypeface);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

这是gradle文件:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.adamvarhegyi.duelsofcodrer"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile('com.android.support:appcompat-v7:25.0.1') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:recyclerview-v7:25.0.1')

    compile('com.makeramen:roundedimageview:2.2.1')
    compile('org.apache.commons:commons-lang3:3.4')
    compile('de.hdodenhof:circleimageview:2.1.0')
}

如果我将扩展更改为简单的 TextView 它工作正常,但是 android studio 建议我必须使用 AppCompatTextView 进行自定义意见。

为什么会发生这种情况?我应该修改什么?

最佳答案

更改这些依赖项

compile('com.android.support:appcompat-v7:25.0.1') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:recyclerview-v7:25.0.1')

compile('com.android.support:appcompat-v7:25.0.0') 

compile('com.android.support:recyclerview-v7:25.0.0')

不知道为什么排除 v4,但如果不是出于某种原因,我会保留它。

不知道为什么会发生这种情况,但最近发生在我身上,修复方法是将 buildToolsVersion 与支持库版本相匹配。

关于java.lang.NoClassDefFoundError : Failed resolution of: Landroid/support/v4/graphics/ColorUtils;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45689714/

相关文章:

java - Android HttpUrlConnection 不支持摘要身份验证?

Android:如何防止 DrawerLayout 将触摸事件传递给底层 View

android - RecyclerView 不显示数据

java - Hibernate 在没有事务的情况下持久化

Java:Spring Boot 类构造函数有太多 DI?

JavaFX:Maven 插件 - 使可执行文件引用 Maven 存储库而不是 lib 文件夹

java - 如何通过 apache poi 添加评论

Android NDK JNI 构建错误 : undefined reference to 'function_name'

android - 是否可以从 .apk 文件中获取 Android.mk 或 native 源文件?

android - 使用 TextInputLayout 时更改 EditText 提示颜色