Reputation: 107
In my library i use consumerProguardFiles
in release build type. My proguard role is :
-obfuscationdictionary proguard-dictionary.txt
-classobfuscationdictionary proguard-dictionary.txt
-packageobfuscationdictionary proguard-dictionary.txt
-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/removal/writeonly,!field/marking/private,!class/merging/*,!code/allocation/variable
-flattenpackagehierarchy
-allowaccessmodification
-renamesourcefileattribute SourceFile
-keepattributes *Annotation*
-keepattributes Signature,MethodParameters,LocalVariableTable,LocalVariableTypeTable
-keepattributes SourceFile,LineNumberTable
-keepattributes Exceptions,InnerClasses
When developers use my library (AAR) in the project and getting release build and use minifyEnabled true
, get proguard-dictionary.txt
is not found:
AGPBI: {"kind":"error","text":"File not found: /Users/USER/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt","sources":[{"file":"/Users/USER
/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt"}],"tool":"D8"}
AGPBI: {"kind":"error","text":"File not found: /Users/USER
/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt","sources":[{"file":"/Users/USER
/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt"}],"tool":"D8"}
AGPBI: {"kind":"error","text":"File not found: /Users/USER
/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt","sources":[{"file":"/Users/USER
/.gradle/caches/transforms-2/files-2.1/12e928515abf78e8a4387fd92c3a399b/proguard-dictionary.txt"}],"tool":"D8"}
How can I use -obfuscationdictionary
without using a dictionary file?
or
How can I fix this?
Upvotes: 2
Views: 2294
Reputation: 11
Post some addtional tips on Dharman's answer for those are confused on it. The rules for proguard dic "-classobfuscationdictionary dic.txt" only add in 'proguard-rules-dic.pro', so it with not be add into lib proguard-rules file.
buildTypes {
debug {
minifyEnabled false
debuggable true
}
release {
minifyEnabled true
debuggable false
// automatically add your proguard rules into your library user
consumerProguardFiles 'proguard-rules.pro'
// the rules for proguard dic "-classobfuscationdictionary dic.txt" only add in 'proguard-rules-dic.pro', so it with not be add into lib proguard-rules file
proguardFiles 'proguard-rules-dic.pro', 'proguard-rules.pro'
}
}
Upvotes: 1
Reputation: 33238
Use the following code:
buildTypes {
debug {
minifyEnabled false
debuggable true
}
release {
minifyEnabled true
debuggable false
// automatically add your proguard rules into your library user
consumerProguardFiles 'proguard-rules.pro'
proguardFiles 'proguard-rules-dic.pro', 'proguard-rules.pro'
}
}
Posted on behalf of the question asker
Upvotes: 1
Reputation: 11
I got the same problem a few days ago, this caused by your aar file which not include the "proguard-dictionary.txt" file, you can check by decompressing your aar file. To solve this problem, you can do like this:
create a folder named "assets" under your library, then put your "proguard-dictionary.txt" file to this folder.
add the "assets" folder as android assets source, you can add the below code to your build.gradle file:
sourceSets {
main {
res.srcDirs = [
'src/main/res'
]
java.srcDirs = [
'src/main/java'
]
assets.srcDirs = [
'assets',
'src/main/assets'
]
}}
And the file tree may like this:
│ build.gradle
│ proguard-rules.pro
│
├─assets
│ proguard-dictionary.txt
Anyway, if you can read Chinese, you can refer to this blog
Upvotes: -1
Reputation: 4628
All the rules mentioned should never go into a file pointed to by consumerProguardFiles
, they look line rules which should go into the proguardFiles
for building the library. Also, Unless you have very special requirements, leaving out all of -obfuscationdictionary
, -classobfuscationdictionary
and -packageobfuscationdictionary
from proguardFiles
for building the library will be the best thing to to.
The consumerProguardFiles
is used for rules which the consumer of the library need to have for the library to work. All these rules will go into the build for the project consuming the library. If you library does not use reflection, then consumerProguardFiles
will most likely not be needed at all.
Upvotes: 3