我正在使用带有3个标签的活动,这在调试中非常有效,但是当我发布应用并生成签名的APK时,我的应用程序崩溃了。
我的布局
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
app:layout_scrollFlags="enterAlways"
app:navigationIcon="@drawable/ic_launcher"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
生成APK“应用已停止”
时出现错误消息java.lang.NoSuchMethodError:
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates (Unknown Source)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (Unknown Source)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (Unknown Source)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup (Unknown Source)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (Unknown Source)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown (Unknown Source)
at android.support.v7.app.AppCompatDelegateImplBase.<init> (Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV9.<init> (Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV11.<init> (Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV14.<init> (Unknown Source)
at android.support.v7.app.AppCompatDelegateImplV23.<init> (Unknown Source)
at android.support.v7.app.AppCompatDelegate.create (Unknown Source)
at android.support.v7.app.AppCompatDelegate.create (Unknown Source)
at android.support.v7.app.AppCompatActivity.getDelegate (Unknown Source)
at android.support.v7.app.AppCompatActivity.onCreate (Unknown Source)
at com.app.sgi.AppMovil.ModuloCosecha.CensarCosecha.onCreate (Unknown Source)
at android.app.Activity.performCreate (Activity.java:6294)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2476)
at android.app.ActivityThread.access$900 (ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1344)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5417)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)
我的gradle文件
defaultConfig {
generatedDensities = []
vectorDrawables.useSupportLibrary = true
minSdkVersion 15
targetSdkVersion 27
return true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.google.android.gms:play-services-maps:11.6.2'
compile 'com.google.maps.android:android-maps-utils:0.4'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
}
请帮助和谢谢。 我无法理解它为什么在开发(调试)中工作但它在生产中不起作用(发布生成的APK)
编辑gradle(不工作)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.1'
useLibrary 'org.apache.http.legacy'
defaultConfig {
generatedDensities = []
vectorDrawables.useSupportLibrary = true
minSdkVersion 15
targetSdkVersion 26
return true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
return true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.0.1'
//compile 'com.android.support:support-v4:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.google.android.gms:play-services-maps:11.6.2'
compile 'com.google.maps.android:android-maps-utils:0.4'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
}
答案 0 :(得分:0)
最后我发现了错误。 我尝试在我的build.gradle中禁用ProGuard生成APK,将minifyEnabled设置为false,如下所示:
buildTypes {
release {
minifyEnabled false
}
}
我生成APK并使用minifyEnabled false完美运行,但当minifyEnabled为true时,我的应用程序失败。
看这篇文章: ProGuard with Android: java.lang.NoSuchMethodError: android.util.Xml.asAttributeSet
我的解决方案是minifyEnabled设置为true:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
并在proguard-project.txt
中添加一行-keep class org.xmlpull.v1.** { *; }