【发布时间】:2015-09-01 10:03:09
【问题描述】:
我面临的问题是我的 android 应用程序在具有 API 5.0 及更高版本的设备上运行良好,但在具有 Kitkat(4.4) 及其相应较低版本的设备上崩溃。我知道它与我的 gradle 中的构建工具有某种关系文件,但仍然无法找出问题。有人可以帮我解决这个问题。
这是我的 gradle 文件,
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.abc.example"
minSdkVersion 10
targetSdkVersion 22
multiDexEnabled true
versionCode 12
versionName "1.0"
}
buildTypes {
release {
multiDexEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android {
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
android {
packagingOptions {
exclude 'META-INF/NOTICE'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT@aar') {
transitive = true
exclude module: 'httpclient'
exclude group: 'httpclient'
}
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:mockwebserver:2.3.0'
compile 'de.hdodenhof:circleimageview:1.2.2'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-maps:7.5.0'
compile files('libs/bitlyj-2.0.0.jar')
}
在构建项目时也会出现此错误,
Caused by: java.lang.NoClassDefFoundError: com.package.R$styleable
at com.package.widgets.StyleableTextView.<init>(StyleableTextView.java:23)
这是 StyleableTextView 类,
public class StyleableTextView extends TextView {
public StyleableTextView(Context context) {
super(context);
}
public StyleableTextView(Context context, AttributeSet attrs) {
super(context.getApplicationContext(), attrs);
UiUtil.setCustomFont(StyleableTextView.this, context, attrs,
R.styleable.com_eywa_wonk_widgets_StyleableTextView,
R.styleable.com_eywa_wonk_widgets_StyleableTextView_font);
}
public StyleableTextView(Context context, AttributeSet attrs, int defStyle) {
super(context.getApplicationContext(), attrs, defStyle);
UiUtil.setCustomFont(StyleableTextView.this, context, attrs,
R.styleable.com_eywa_wonk_widgets_StyleableTextView,
R.styleable.com_eywa_wonk_widgets_StyleableTextView_font);
}
}
这是 attrs 中的样式,
<resources>
<attr name="font" format="string" />
<declare-styleable name="com.package.widgets.StyleableTextView">
<attr name="font" />
</declare-styleable>
</resources>
【问题讨论】:
-
您能否更具体地了解该错误?发布堆栈跟踪
-
是的,当然。我在“values”文件夹中的 attrs 文件中为自定义 textview 创建了一个自定义样式。在具有 5.0 但在 API 4.4 及更低版本的设备中检测到样式在您的应用中找不到自定义 TextView 以及
错误,我很确定我已将其用作“com.package.CustomTextView” -
值文件夹是否有版本计数器?比如/values-v22?如果是这样,您将需要为其他版本制作一些东西,或者为 Lollipop 设备添加自定义样式。
-
@Knossos 不,它没有版本计数器..
-
@force我会用它的错误堆栈更新帖子。请看看。
标签: android sdk android-gradle-plugin build-tools