java proguard-rules.pro 文件上的 FileNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28168161/
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
FileNotFoundException on proguard-rules.pro file
提问by Rikki Tikki Tavi
I'm using Android Studio v.1.0 My build file :
我正在使用 Android Studio v.1.0 我的构建文件:
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
but when I try to make a release build, I get an error : Error:Execution failed for task ':app:proguardRelease'.
但是当我尝试进行发布版本时,出现错误:错误:任务':app:proguardRelease'的执行失败。
java.io.FileNotFoundException: F:....\app\proguard-rules.pro (File not found)
java.io.FileNotFoundException: F:....\app\proguard-rules.pro(找不到文件)
I think, that proguard-android.txt is a part of Android SDK, am I right ?
我认为,proguard-android.txt 是 Android SDK 的一部分,对吗?
And why Android Studio can't find it ?
为什么 Android Studio 找不到它?
I also tried proguard-android.pro - the same result
我也试过 proguard-android.pro - 结果相同
采纳答案by Rikki Tikki Tavi
I've created my own proguard-android.pro file and that works properly for me :
我已经创建了我自己的 proguard-android.pro 文件,它对我来说正常工作:
-dontwarn org.apache.commons.**
-dontwarn com.google.**
-dontwarn com.j256.ormlite**
-dontwarn org.apache.http**
-keepattributes SourceFile,LineNumberTable
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
-keepattributes Signature
# GSON Library
# For using GSON @Expose annotation
-keepattributes *Annotation*
# 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.** { *; }
# Google Map
-keep class com.google.android.gms.maps.** { *; }
-keep interface com.google.android.gms.maps.** { *; }
回答by Andrey
If you don't need any specific ProGuard configuration:
如果您不需要任何特定的 ProGuard 配置:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
(The warning might happened)
(警告可能发生)
Or specify "rules" and put it here:
或者指定“规则”并将其放在这里:
.../app/proguard-rules.pro
For example I use "Butter Knife" and my proguard-rules.pro looks like:
例如,我使用“黄油刀”,我的 proguard-rules.pro 看起来像:
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}
Or, possibly you can leave build.gradle file as it is (if you don't like warnings )), And just put an empty proguard-rules.pro to that location.
或者,您可以保留 build.gradle 文件原样(如果您不喜欢警告)),然后将一个空的 proguard-rules.pro 放在该位置。
回答by Sagar Trehan
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Following line in build.gradle file of your app module indicates the script of proguard needs to apply to your release build. It has two files:
应用程序模块的 build.gradle 文件中的以下行表示需要将 proguard 脚本应用于您的发布版本。它有两个文件:
proguard-android.txt
: is the default android proguard file, can be found in D:\SDK\tools\proguard directory of SDK.- 'proguard-rules.pro': It contains your application specific proguard script. You need to create this file in the root folder of your application. All your application specific proguard should be inside this file.
proguard-android.txt
: 是android默认的proguard文件,可以在SDK的D:\SDK\tools\proguard目录下找到。- 'proguard-rules.pro':它包含您的应用程序特定的 proguard 脚本。您需要在应用程序的根文件夹中创建此文件。所有特定于应用程序的 proguard 都应该在这个文件中。
回答by user3068659
please check your 'proguard-rules.pro' inside your root project folder. I your project exported from eclipse you must create 'proguard-rules.pro' inside root project folder.
请检查您的根项目文件夹中的“proguard-rules.pro”。如果您的项目是从 Eclipse 导出的,您必须在根项目文件夹中创建“proguard-rules.pro”。
回答by cici
A workaround is to download one of the following:
解决方法是下载以下之一:
http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz
http://dl.google.com/android/android-sdk_r22.6.2-windows.zip
http://dl.google.com/android/android-sdk_r22.6.2-macosx.zip
And copy over the following files:
并复制以下文件:
tools/hprof-conv
tools/support/annotations.jar
tools/proguard
回答by shyam
Hope this answer may be helpful in future
希望这个答案将来可能会有所帮助
GoTobuild.gradle(Module:app)
去build.gradle(Module:app)
Remove this part frombuildTypes
将这部分从buildTypes
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}