Generating a Pro Guard configuration file with Android Studio - android

I am using Android Studio since 0.1.0 ... I just learned yesterday that Pro Guard seems to be integrated in newly created projects. Unfortunately this is not true for my project (which was a former Eclipse project). I didn't know of Pro Guard until I started working with Android Studio. And now I am looking for examples on how to use Pro Guard with Android Studio. Unfortunately the Android Dev documentation is only mentioning situations where the configuration file is already created. Is there a possibility to get Android Studio to create a configuration file to an already existing project?

I was also not able to do it through Android Studio. However, this worked for me.
Add the following sections to the "android" section of your build.gradle file, filling in your own implementation details where appropriate.
android {
...
signingConfigs {
releaseConfig {
storeFile file("/dir/to/your.keystore")
storePassword "xxx"
keyAlias "yyy"
keyPassword "xxx"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../your_proguard_file.txt'
signingConfig signingConfigs.releaseConfig
}
}
}
In your project folder, run ./gradlew clean and ./gradlew assembleRelease

You can copy the default Proguard configuration file to your project.
sdk-location/tools/proguard/examples/android.pro — copy and paste it as proguard.cfg in your project. Then choose it when AS asks for the config file path.

The complete ProGuard configuration that is generated by your rules (.pro) file can be saved by appending the -printconfiguration command to your existing rules. i.e.
-printconfiguration 'C:\Example\File\Path\proguard-configuration.txt'

Related

Android app apk not getting installed from file filemanager

When I share my apk through Google Drive or any means App is not getting installed on some phones. But when I install it through ADB it is getting installed. What could be the problem?
there are many reason , maybe you use native code , or issue with signing.
try to install though ADB in release variant and check the error .
in android section at your app level gradle file "build.gradle module app add your signing config
.........
android {
signingConfigs {
config {
storeFile file('path to your keystore file')
storePassword 'keystorePassword'
keyAlias 'alias'
keyPassword 'aliesPassword'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
.......
then from the left side click build variant and choose release
now run your app and you should get the same result as install the APK from file manager or what ever .
If you are using Android studio 3.0 above version and trying to build an APK then go to
Go to build
2: Build bundles
3: Build APK(s)
and then share the build. It will surely get installed in any devices.
Just make sure Device has allowed APK install from other resources.

Libgdx - Gradle Android debuggable

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.

Android studio - release APK for flavor

I'm new to Android Studio and running a debug build on a device is working fine, however to test in app purchasing (and obviously to release) I need a release build signed with the normal key. I can make an APK using Build -> Generate signed APK, however the package name seems to be incorrect. Here's my build file:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 9
testPackageName "com.company.common.common"
testInstrumentationRunner "android.common.InstrumentationTestRunner"
}
signingConfigs {
releaseConfig {
storeFile file("filname")
storePassword "password"
keyAlias "alias"
keyPassword "password"
}
}
buildTypes {
debug {
packageNameSuffix ".debug"
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.releaseConfig
}
}
productFlavors {
Flavor1 {
packageName "com.company.test"
}
}
}
dependencies {
// some dependencies
}
Note the package name overridden in the flavor. That flavor has no manifest; the only manifest is under main, and specifies a package of com.company.common. If I use Android to create a com.company.test APK and install it on a device, then generate an APK from Android Studio and install it, I end up with two apps on the device rather than the second replacing the first. This indicates that the package names are different, I assume because Android Studio is producing an APK with a package of com.company.common. Not sure how to verify that though.
When I just build the project, I get a debug APK but no release APK. How do I get a release APK with the correct package name? I just ran the app from Android Studio and it says it's installing com.company.test.debug, and that it needs to uninstall the app before installing. So now I'm thinking the generate signed APK generated a build with the debug package.
So far this is the issue that's preventing me from moving to Android Studio and gradle. Once I get past this I think I'm clear to move everything over so I'm hoping someone can help me figure it out!
Before you choose the Generate Signed APK option, go into the Build Variants window and choose the Release build variant. The Generate Signed APK command takes whatever the current build type is selected there and signs it. This obviously isn't what you want in this case; bug https://code.google.com/p/android/issues/detail?id=56532 is requesting improvements there.

Android Studio: Signing issue after upgrade

I recently upgraded my android studio from 0.2.6 to 0.2.11. The Build - > "generate signed apk" wizard which was opening up in 0.2.6 is not coming up here. Instead it shows a dialog like :
For Gradle-based projects, the signing configuration should be specified in the Gradle build scripts.
See the Gradle User Guide for more info.
I even added the below lines in build.gradle file:
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
foo {
debuggable true
jniDebugBuild true
signingConfig signingConfigs.myConfig
}
}
Could anyone please tell me what could be the issue?
Or also could you please let me know how to downgrade my studio?
Thanks
A temporary fix for your issue is to restart Android Studio. After a cold start, Android Studio will let you access the "generate signed apk" wizard once before again warning you that you have to change your build.gradle.
As Shai mentioned, this will be fixed in a future release. Please see the links in his post.
This issue is got fixed in Android Studio v 0.2.13 as expected.
Bug fixed by Android Studio Developer Team
Google Android Thread
I copied gradlew from the android studio to my project root directory
Then I added this to my build.gradle
android {
...
signingConfigs {
release {
storeFile file("mykeystore")
storePassword "mypassword"
keyAlias "my alias"
keyPassword "mypassword"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
Then I did
gradlew assembleRelease
from my project root directory
This way I got the signed apk in build/apk
Too bad I wasn't able to do the same via IDE
I ended up just using "gradle installRelease" and coping the release APK from build/apk folder.
I am not sure why we are getting this, I do have my signingConfigs setup properly in build.gradle.

Android Studio "Project Structure" window not working?

Loads of tutorials for Android Studio need me to use the "Project Structure" window (File > Project Structure), but whenever I try to open it, I get an error "We will provide a UI to configure project setting later. Until then, please manually edit your build.gradle file(s.)".
Does anyone know if it's like this for everyone (in which case, what do those tutorials mean by File > Project Structure?), or just me? I've had the same error on Windows and Linux.
One of the tutorials: How do I add a library project to Android Studio?
Before Android Studio, IntelliJ Android plugin users used to use the Project Structure dialog to add/remove modules from their projects.
Android Studio aims to have a single model for building your application from both the command line and from the IDE. So if you have to modify the project structure, the correct way to do it is to modify your build.gradle (and/or settings.gradle) build scripts and reimport the project.
Eventually (within a few months), Android Studio will hook up the project structure dialog to automatically edit the gradle build scripts for you, or will provide a different UI, just like the error message says.
You'll find the gradle plugin user guide at http://tools.android.com/tech-docs/new-build-system/user-guide to be helpful in figuring out how to add libraries to your gradle build scripts.
There are currently some bugs with the UI in android studio project structure settings related to updating the Gradle. Right now whatever I enter into the project structure fields do not save or update the gradle files. What did work for me was writing the settings directly into the build.gradle
The gradle files are basically xml files that are generated (dynamic) instead of static.
I tried forever in the project structure UI to set up application signing for debug, eventually to get it to work I added,
android {
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
foo {
signingConfig signingConfigs.myConfig
}
}
}
The android developers guide for configuring gradle will help you get up to speed.
http://developer.android.com/tools/building/configuring-gradle.html
refer to the Gradle documentation for the parameters you are looking for
http://tools.android.com/tech-docs/new-build-system/user-guide
There are currently some bugs with the UI in android studio project structure settings related to updating the Gradle. Right now whatever I enter into the project structure fields do not save or update the gradle files. What did work for me was writing the settings directly into the build.gradle
The gradle files are basically xml files that are generated (dynamic) instead of static.
I tried forever in the project structure UI to set up application signing for debug, eventually to get it to work I added,
android {
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
buildTypes {
foo {
signingConfig signingConfigs.myConfig
}
}
}
The android developers guide for configuring gradle will help you get up to speed.
http://developer.android.com/tools/building/configuring-gradle.html
refer to the Gradle documentation for the parameters you are looking for
http://tools.android.com/tech-docs/new-build-system/user-guide

Categories

Resources