![](/img/trans.png)
[英]java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/graphics/drawable/DrawableWrapper;
[英]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
配置,应将其替换为implementation
或api
。
您最终的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.