I have added gradle build to Android app, and can launch from Android Studio.
gradlew build produces debug and released (signed, minified with proguard) versions.
buildTypes {
debug {
zipAlignEnabled true
versionNameSuffix "-" + buildDateTime()
}
release {
minifyEnabled true
// Eclipse project.properties # proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
zipAlignEnabled true
signingConfig signingConfigs.release
versionNameSuffix "-" + buildDateTime()
}
But when I adb install on device the release version it crashes on start.
How can I run/debug release version of app from Android Studio to find exact place of problem?
Or can I debug manually released signed apk in Eclipse?
There's a window called 'Build Variants' where you can choose, which version you want to be installed on your emulator/device.
You also have to add debuggable true to your release build to be able to debug it.
Android Run .apk
View -> Tool Windows -> Build Variants
Additionally you can use Gradle toolbar or ./gradlew tasks --all
//install on device(which is running)
Tasks -> install -> install<build_varaiant>
//open
adb shell am start -n <package_name>/.<activity_name>
*Android Studio v4.2 does not contain Tasks by default. You should disable Do not build Gradle task list during Gradle sync in Preferences -> Experimental
You can use Profile or Debug APK option in android studio and debug your release apk.
Related
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.
I updated Android studio from Preview 2 to Preview 3 and now I get this error when I try to generate a release APK:
Error:A problem was found with the configuration of task ':app:packageProdRelease'.
> File '/Users/jay/repositories/test/app/build/intermediatesError:A problem was found with the configuration of task ':app:packageProdRelease'.
> File '/Users/jay/repositories/test/app/build/intermediates/res/resources-prod-release-stripped.ap_' specified for property 'resourceFile' does not exist.
I've read that it might be related to instant run feature so I disabled it and still the same error. And then, I tried to set shrinkResources attribute to false and then It works. BUT when I tried uploading the apk in Google Developper Console, it says my apk is not Zipaligned...
Wherever you are Google Developper, Help me out! :O
This problem occurs to me if I am using gradle 2.2.0-alpha3. I found a workaround to this problem. You can solve this by disabling shrinkResources and zipalign in gradle and then run zipalign using command line.
build.gradle:
shrinkResources false
zipAlignEnabled false
Run the zipalign command manually:
<your-android-sdk-path>/sdk/build-tools/23.0.3$
./zipalign -v 4 <your-input>.apk <your-output>.apk
Edit:
I just have a try on using older version of gradle 2.1.0, it works without this problem. zipalign problem in gradle 2.2.0-alpha3 is mentioned in this SO thread as well.
I was trying to use com.android.tools.build:gradle:2.2.3 in the project build.gradle file which was causing me issues.
I found that I was able to successfully generate a signed APK whenever I changed it to com.android.tools.build:gradle:2.1.0
According to a Google Engineer, enabling both minifyEnabled and shrinkResources should work:
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I had ProGuard running for release builds when Cordova built with Ant, but now that Gradle is used my project's release builds aren't being obfuscated (my "cordova build --release android" output shows a step for :CordovaLib:mergeReleaseProguardFiles, but no other proguard/minification/obfuscation entries).
With Ant, my project.properties file referred to my proguard-project.txt file using the proguard.config parameter.
How do I configure this to work now that Cordova uses Gradle?
Have a look at the updated Proguard Documentation, you now have to change the build.gradle file.
Change the buildType release section to something like this
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
I get the message: You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play. Learn more about debuggable APKs.
I generate my APK with Android Studio, Build->Generate Signed APK. I created a Keystore.
With a powerful gradle build system in android studio you can do it without even touching your code. You can also make your debug build with debuggable false to test what differences are
buildTypes {
debug {
runProguard false/true
proguardFile getDefaultProguardFile('proguard-android.txt')
debuggable false/true
}
release {
runProguard true/false
proguardFile getDefaultProguardFile('proguard-android.txt')
debuggable false/true
}
}
Power of Gradle.
Note : You wont be able to see the process in the left pane of DDMS under device info even the application running in device, if it has debuggable false in build configuration.
If you have the tag android:debuggable="true" in your application manifest, or if you don't have it in, try changing it/putting this in your application manifest tag:
android:debuggable="false"
Check DEBUG value in BuildConfig.java file in gen folder. Sometime if we are not doing clean build this value remains true.
Best is to do a clean release build.
If you're using Gradle (As you should) set the debug and release variables, then go to your build variables tab and select release flavor.
Build the project, and if you set everything up correctly, your apk should be in the build/apk folder of your project.
I was having this same problem. Anymore, android:debuggable in the manifest file is deprecated if you are using Android Studio; you shouldn't have it there. The problem in my case was that the system was incorporating debug versions of some component classes, which did not get rebuilt (as I assumed they would) when I switched from doing debug to release builds. Everything worked once I selected (from the menus) Build->Clean Project.
I want to build my gradle project with a certain buildtype and deploy it on device with a single command.
My build.gradle is setup for multiple buildtypes such as live and release.
I worked with maven before and i look for an equivalent of:
mvn clean install -P release android:deploy android:run
Here is the command to build and deploy through a specified BuildType. ( Thank you Varun! )
gradle installProfilename
Where Profilename of course would be the name of the BuildType specified in build.gradle
Example.:
gradle installRelease
Would build with the release profile:
buildTypes {
release {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.main
. . .
}
Addition.:
Gradle can show you what tasks are available.:
gradle tasks