【发布时间】:2015-04-30 16:25:24
【问题描述】:
我已将我的应用从 ADT 迁移到 Android Studio,因为它成为了官方 IDE。
但是我最近发现可以反编译,而且我的来源很清楚。
我在 Eclipse 中花了很多时间来混淆我的 apk,所以我仍然有我的 Proguard 文件,这很好
proguard-project.txt:
##---------------Begin: proguard configuration common for all Android apps ----------
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#-injars bin/classes
#-injars libs
#-outjars bin/classes-processed.jar
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable, LocalVariableTable,LocalVariableTypeTable
-repackageclasses ''
-keep public class * extends android.app.Activity
-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Preserve all native method names and the names of their classes.
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class * {
public protected *;
}
##---------------End: proguard configuration common for all Android apps ----------
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------
##---------------Begin proguard configuration for Google Maps --------------------
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class org.** { *; }
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
##---------------End proguard configuration for Google Maps --------------------
##---------------Begin proguard configuration for my libs -----------------------
-keep class com.todddavies.components.progressbar.** { *; }
-dontwarn com.todddavies.components.progressbar.**
-dontwarn org.apache.**
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keep class com.myapp.mobile.Pdv.** { *; }
-keep interface com.myapp.mobile.Pdv.** { *; }
#Disable logging
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
}
-keep class com.myapp.mobile.vo.Captura { *; }
-keep class com.myapp.mobile.vo.Formulario { *; }
-keep class com.myapp.mobile.vo.Metrica { *; }
-keep class com.myapp.mobile.vo.Pdv { *; }
-keep class com.myapp.mobile.vo.Proyecto { *; }
-keep class com.myapp.mobile.vo.Producto { *; }
我的 build.gradle 是:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.myapp.mobile"
minSdkVersion 16
targetSdkVersion 20
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
compile project(':progressWheel')
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/crashlytics.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.3.3.jar')
}
我看了几篇帖子,都说你必须激活它:
minifyEnabled 真 但是我的已经激活了……
感谢@Robert Rowntree,我还意识到运行 ./gradlew clean assembleRelease 后 build/outputs/mapping/release 是空的
不过,我还是无法让 Proguard 工作???没有proguard,我不可能发布我的应用程序!!!
有什么想法???
编辑 1:当我运行 gradlew build 时,我得到 BUILD SUCCESSFUL
【问题讨论】:
-
1) 删除“所有项目通用”proguard 代码。它已经包含在
getDefaultProguardFile('proguard-android.txt')中(如果它仍然合适,请验证该文件,或者保留在那里找不到的文件)。 2) 为什么不针对普通的“22”进行编译?从来没有真正理解过针对 Google API 进行编译的意义。你能在评论中解释一下吗? -
1. Proguard.txt 里面什么都没有。 2. 在这个开发阶段我不会更改API级别,我会在稳定版发布后更新它。无论如何,它不会解决我的问题,只是给我创造新的。 3. 我使用 Google API 进行编译,因为我在我的应用程序中运行 Google 地图(并且您需要为此运行 Google Play 服务)
-
1. 没有
proguard.txt。只有具有已读取规则的文件是来自 SDK 目录的proguard-android.txt和来自您的项目目录的proguard-project.txt(根据您的设置)。我建议清理项目 proguard 规则,因为它看起来最初也包含通用规则。 2. 这当然是明智的。 3. 您将通过此行compile 'com.google.android.gms:play-services:+'包含所有最新(是的,动态)Google Play 服务 API。Google Inc.:Google APIs:21仅用于设置具有 Play 服务支持 afaik 的模拟器。 -
好的,如果你运行build并且输出中没有任何内容,那么proguard没有问题,但构建过程一般。再次:在项目根目录中打开命令行并运行
gradlew build。这将构建您的应用程序的所有变体(调试和发布),如果出现错误,您将在控制台输出中看到它。在原始问题的末尾添加该错误。 -
你一直提到
outputs/mapping,你到底希望在那里?我问是因为我从来没有听说过。只需从outputs/apk获取发布 apk 并尝试反编译它。发布 apk 应该被混淆,因为您在build.gradle中为发布构建启用了 proguard,并且构建过程成功。 (尝试在启用和禁用 proguard 时比较 apk 文件大小。)
标签: android eclipse android-studio proguard