previous installed AndroidStuio version was :2.1.3 but after update to 2.2 and update gradle, building gradle has a problem Because of the proguard name.
Before, for release .Apk i use a custom proguard config with this way:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('fileName.txt')
}
}
but after update AndroidStudio 2.1.3 to 2.2 this error occurs:
Error:(17, 0) User supplied default proguard base extension name is unsupported.
Valid values are: [proguard-android.txt, proguard-android-optimize.txt]
Open File
Notice That : After update settings and config files imported from previous version And SDK folder path not chnage
old way!
Unfortunately and finally, I had to use old version of AndroidStudio(2.1.3) and
this work but not is solution for AndroidStudio 2.2
way 1 :
After several tests I found that I should set complete path to proguard file like following config :
in build.gradle(module:app) :
buildTypes {
release {
minifyEnabled true
proguardFile ('FullPath/.../configFileName.txt')
}
}
, and no need to using getDefaultProguardFile before path.
Too , you can paste your config file to ...\appName\app and chanage proguardFile to :
proguardFile ('configFileName.txt')
Actually , default path is .../appName/app and if you put just configFileName , this will search file name in default project path.
in previous version I had't this problem and default gradle path was ...\SDK\tools\proguard
update
way 2 :
in below image and step 4 you can browse and select ProguardFile for debug or release
And in build.gradle(module:app) file , ProguardFile path will add automatically
try changing like the below
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt') fileName.txt // or file('{path_to_file}/fileName.txt')
}
}
guess it supports proguard-android.txt or proguard-android-optimize.txt for default proguard file as it stated in the message.
proguard-android.txt was located in ~/Library/Android/sdk/tools/proguard in my case.
I think android studio retrieve that file. or you may make proguard-android.txt in the project folder and add the path in getDefaultProguardFile parameter (I haven't tried it though).
After then you can add your additional proguard file by adding like the code above.
Related
I recently upgraded my hybrid MobileFirst app's mfp plugins to 8.0.20180408, and my cordova-android plugin to 7.0.0. When I did a debug build of the app, the build succeeded, but the moment I did a release build (signed apk) the process generated a lot of proguard warnings. When I downgraded the cordova-android version to 6.4.0 the release build succeeded.
The mobilefirst cordova plugin is supposed to support cordova-android v7 Since the MobileFirst iFix 8.0.0.0-MFPF-IF201804051553, as per the iFix release notes, but it seems that there is a problem with the it in this ifix.
I did some investigation into the proguard configuration file as there seem to be a problem with the gradle build process finding the right proguard configuration file.
The mfp cordova plugin contains a proguard configuration file called proguard-project-mfp.txt, which is added to the android platform of the hybrid project. The plugin also contains a gradle file
dev-build-extras.gradle
which specifies the location of the proguard configuration file. The proguard file specified in the configuration has no path attached to it:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-mfp.txt'
It seems that in cordova-android 7.x, when the android platform is generated, it copies the proguard-project-mfp.txt file to the directory platforms/android/app/src/main/ whereas the dev-build-extras.gradle file is located in the directory platforms/android/cordova-plugin-mfp/
This means that gradle cannot find the proguard configuration file. Updating the proguard configuration file location in the gradle file relative to the gradle file seems to solve the problem and allows for the signed apk to be built.
In summary, update the file
platforms/android/cordova-plugin-mfp/dev-build-extras.gradle
with the following
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-mfp.txt'
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../app/src/main/proguard-project-mfp.txt'
Your dev-build-extras.gradle file should now look like this:
android {
buildTypes {
release {
minifyEnabled true
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project-mfp.txt'
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../app/src/main/proguard-project-mfp.txt'
}
}
.
.
.
}
I would like to make my app debuggable.
When I deploy to my nexus 5x I get this error:
Error running AndroidLauncher: Cannot debug application from module android on device lge-nexus_5x-(code here). This application does not have the debuggable attribute enabled in its manifest. If you have manually set it in the manifest, then remove it and let the IDE automatically assign it. If you are using Gradle, make sure that your current variant is debuggable.
If I add the debuggable="true" attribute to the android tag in my manifest it works.
But I'm forgetful, so I'd rather do it the proper way with gradle.
I've tried to add a lot of the things I've found on the internet to both my Android module build.gradle, and my project's root level build.gradle.
All to no avail.
What should work?
Thanks,
Chase
On an tangent, I also tried running my HTML module using the instructions from their site, and it says it's failing because I'm using java 1.7 features but the gradle source is 1.6. I've also tried googling that to no avail. I was adding some lines like this:
sourceCompatibility 1.7
targetCompatibility 1.7
You can use build types (Build Variants) in your android gradle file:
project/android/build.gradle
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
}
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
minifyEnabled true
pseudoLocalesEnabled false
debuggable false
signingConfig signingConfigs.AndroidKey
}
}
* There is some proguard stuff and signing config you might not need. Just remove from the release build variant.
You don't need any other configuration in other files. You can see the full source I used in my project here.
If you are using Android Studio you can change between your build variants here:
When you run the project if release is selected it will install the non debugable apk in your device. Otherwise, if debug is selected it will install the debugable apk. Both can be installed at the same time. It will show the app twice in your device.
The problem is that it should be debugable by default. You could remove the debuggable true line and the debug build variant should still be debugable.
If it does not work paste your manifest and your build.gradle files here so we can see what is going on.
You can look all theses files in my project. It is also a libGDX project, but it don't have the HTML module.
The Build Variant docs might be helpful.
Under minifyEnabled I changed from false to true.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Then I generated a signed APK and used javadecompilers.com to see if files had been altered and the classes,variables, etc were still the same.
I also attempted to use dex2jar, but the terminal stated that no files were found. I also attempted to export my android studio project as a jar file.
Any other suggestions ?
Did you build a release version of your application? As default for minifyEnabled is false, so if you build a debug version, that would explain it.
Other than that, could you post your proguard-rules.pro file? It might contain exceptions that are too broad.
I've used dex2jar many many times, and it's worked for me.
I'm on a mac, so i simply run "./d2j-dex2jar.sh app.apk" command, and then open the resulting jar file in a program called JDGui, there you can see all the files in the jar file.
I'm trying to use proguard but it keeps telling me to look for a project.properties folder and post this code
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
the thing is I can't locate it. Where can I find it?
If you are using Android Studio then you will not have a project.properties file as it uses the gradle build system.
You can add ProGuard into your gradle build as follows:
buildTypes {
release {
minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
These lines should be automatically generated when you create a new Android Studio project, although minifyEnabled is set to false.
I am new to Android and Android Studio.
During my learning I came across the Google Play Services for Ads and all.
I tried to enable proguard in my project but reading the below link proguard.
The problem is that I am not able to find proguard-project.txt or proguard.cfg in my project structure...
Instead there is a proguard-rules.txt in my project structure...
How can I find these missing files and configure proguard in my project...
Please help...
Use the proguard-rules.txt file instead. Proguard doesn't attach any special significance to the name of its rule input files; it uses whatever's set up in your build files, which for new projects created in recent versions of Android Studio, is:
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
The proguard-android.txt file lives inside your SDK, and contains reasonable Android-wide defaults that all projects should use.
I had the same problem when I started using Android Studio
You can't see the ProGuard files because you are previewing you project in a non Project file mode. Which most probably will be Android view mode.
You have to change the mode by clicking on the drop down list of the Android selection and select Project Files to see all the files in the project as the following:
Then you will be able to see the hidden files in the Android project structure view mode.
And here is a good example for the ProGuard
You can find proguard-project.txt in
C:\Users\"USER"\AppData\Local\Android\android-studio\sdk\tools\proguard
"USER" is the name in you will see when you click on c-drive \users \yourname
the code posted previously must be corrected to the following according to your use:
buildTypes {
release {
minifyEnabled true //according to your use
// or
minifyEnabled false //according to your use
// runProguard false ** NOT USED ANYMORE, replaced by minifyEnabled
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I couldn't find this proguard-rules.txt anywhere on my Windows machine with Android Studio. I did however find a LayoutExample\app\proguard-rules.pro file. This is probably because I had imported my project from Eclipse, so Android Studio didn't create one automatically. So what I did was:
1 - Copy the proguard-rules.pro from the example project to the same folder as build.gradle for my project (you can either search for this file on your machine or create an empty project)
2 - Edit the code in build.gradle to use this file instead of proguard-rules.txt, e.g.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
Sync gradle, then Build > Build APK. Worked fine for me.
proguard-rules.txt can be found with terminal command on OS X (should be similar on windows as well)
$ locate proguard-rules.txt
On my machine the output is:
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/AndroidWearModule/root/proguard-rules.txt.ftl
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/proguard-rules.txt.ftl
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewAndroidTVModule/root/proguard-rules.txt.ftl
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewGlassModule/root/proguard-rules.txt.ftl
You can place this file by removing the extra extension beyond txt. Here is what it looks like so you can create your own and place in your android project.
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdkDir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
I had the same problem after updating android studio , I couldn't import my project to new version.
change in the gradle build file.
buildTypes {
release {
minifyEnabled false *//change to this not runProguard false*
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}