仅当使用proguard + gradle构建时才会出现此问题。如果从android工具和proguard导出 - 所有引用都映射正确。Proguard与Gradle messes id的定义
问题:
我已经在库项目
<resources>
<item type="id" name="background" />
</resources>
而且活动布局定义的一些ID的是在主体工程
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/splash"
tools:ignore="ContentDescription" />
的NullPointer
正在使用ProGuard抛出建成后,在主项目的活动
this.findViewById(R.id.background).setOnClickListener(new View.OnClickListener() {
不要建议我重新定义id's,因为这是一种错误的方法,并且无论如何都会崩溃。
android:id="@+id/background"
UPDATE:事实证明,它搅乱主项目的布局定义如下
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/backgroundTEST"/>
即使ID也崩溃与NullPointerException
。我认为这是因为库项目,因为最前面的一个那是一个来自图书馆项目的失败者。
的配置如下
的$ANDROID_HOME/tools/proguard/proguard-android.txt
是
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-dontwarn android.support.**
的proguard-project.txt
为我的项目
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.support.v4.app.FragmentActivity
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
从build.gradle
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile 'proguard-project.txt'
signingConfig signingConfigs.release
}
}
我担心的是,也许它不包括getDefaultProguardFile('proguard-android.txt')
。 那么,对于一个实验我已经复制粘贴proguard-android.txt
内容proguard-project.txt
及后仍然
gradle clean
gradle assembleRelease
坠毁。
我也是。要在我的答案中更新这个。 –
我实际上包含了默认配置。对不起,我没有提及。我已经用更多的细节更新了答案。 –