Android Studio - ProGuard "java.io.IOException ...bin\classes (No such file or directory)"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26028171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Studio - ProGuard "java.io.IOException ...bin\classes (No such file or directory)"
提问by Georgi Angelov
So I am running ProGuard for the first time and I am getting a weird error:
所以我第一次运行 ProGuard,我收到一个奇怪的错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:proguardRelease'.
> java.io.IOException: Can't read [C:\Users\Some\workspace\MyApp\app\bin\classes] (No such file or directory)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Here is my gradle:
这是我的毕业证书:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.+'
compile 'com.google.android.gms:play-services:4.3.23'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.viewpagerindicator:library:2.4.1@aar'
compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
compile 'com.squareup.picasso:picasso:2.3+'
compile 'com.github.castorflex.smoothprogressbar:library:0.4.0'
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
my proguard-rules.txt:
我的 proguard-rules.txt:
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-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.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*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
回答by Eric Lafortune
The Android Gradle plugin already specifies all input and output for you, so you must notspecify -injars
, -outjars
, or -libraryjars
.
Android的摇篮插件已经指定了所有输入和输出你,所以你必须不指定-injars
,-outjars
或-libraryjars
。
Moreover, the file proguard-android.txt
in the Android SDK specifies all generic Android settings for you, so you shouldn't specify them again.
此外,proguard-android.txt
Android SDK 中的文件为您指定了所有通用的 Android 设置,因此您不应再次指定它们。
Essentially, your file proguard-rules.txt
can be empty, except for any application-specific settings to make sure any reflection continues to work.
本质上,您的文件proguard-rules.txt
可以为空,但任何特定于应用程序的设置除外,以确保任何反射继续工作。
回答by user3068659
you no need these lines, because these are already defined.
你不需要这些行,因为它们已经定义好了。
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar