簡體   English   中英

java.lang.NoClassDefFoundError:無法解決以下問題:Landroid / support / v4 / graphics / ColorUtils;

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

Android 5.1.1 java.lang.NoClassDefFoundError ,但我在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與支持庫版本匹配。

我懷疑該問題與使用較舊的支持庫或通過排除support-v4模塊有關。 另外,現在不建議使用 compile配置,應將其替換為implementationapi

您最終的gradle配置應如下所示,

implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support:recyclerview-v7:26.0.1'

最后,請確保使用/不排除support-v4模塊再次進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM