Gradle build and deploy specific buildtype - android

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

Related

How to create build variants in Flutter Android so that each build variants have different app id?

I need to have 3 different APKs (dev, UAT, prod), each targetting different Firebase database. But on each Firebase project, I need to supply a permanent app id. That means I need to have 3 build variants that each deploying APK with different app id. But on Android Studio, I seem can't find such a way to build variants for Flutter for this purpose (the build variants section is empty).
What I'm looking for is not just a different entry point and different constants, but different app id altogether. From what I gather, changing app name and app id in Flutter requires 6-steps like this. I don't think doing these 6-steps each time I want to change build scope is an efficient and correct way to handle this.
In Flutter, you should select build flavors instead of build variants (combination of build flavor and build type). Flutter run has a --flavor option, but not buildType.
Specify build flavors:
In build.gradle below defaultConfig {}:
android {
...
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
debug {
applicationIdSuffix ".debug" // Optional, you don't need to create a separate applicationId for debug.
signingConfig signingConfigs.debug
}
}
flavorDimensions "default"
productFlavors {
dev {
applicationIdSuffix ".dev"
}
qa {
applicationIdSuffix ".qa"
}
prod {
}
}
}
Run your Flutter app with specific build flavor:
On the command line: use flutter run --flavor flavorName, or
In Android Studio: Run/debug configuration Drop Down → Edit Configuration... → Additional run args: → Add --flavor dev or --flavor qa or --flavor prod
Confirm the applicationId has changed. I use package_info_plus for this:
Add package_info_plus: ^1.0.4 to pubspec.yaml
Add the code somewhere:
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
print("Package name: ${packageInfo.packageName}");
});
The packageName will have both the build flavor and build type. In my case, because of applicationIdSuffix in both buildTypes and productFlavors, com.example.dev.debug. You could remove applicationIdSuffix ".debug" if you don't need/ want it.
Now we can have separate build flavor directories with their own google-services.json.

how to create non-debuggable release build for android using cordova command line

cordova version 6
with gradle 2.3.1
I have generated the release build using command
cordova build --release android
,signed the apk using
release-signing.properties file which is in folder platforms/android,
in Android menifest file there is no attribute like application:android:debuggable="true/false" when I tried to make it false it throwing error: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one [HardcodedDebugMode]
so what we have to do so that generated apk(release version) will not be debuggable either on emulator or on real device
If your are using gradle the release build is default non-debuggable and you can add it explicitly to your build.gradle :
buildTypes {
release {
...
debuggable false
...
}
}

Proguard with Cordova Android 4?

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'
}
}
}

Android Studio: Multiple APKs for Multiple Modules

In Android is there a way to generate signed APKs for all modules in a project.
E.g. I have following project
Project
-- Library Module
-- Module 1
-- Module 2
-- Module 3
I want to generate APKs for all 3 modules in one command. Currently I have to separately use Generate Dialog for all 3 which takes a lot of time.
Yes you can generate multiple apk files with gradlew.
Open Terminal Window in Android Studio and run following commands:
1- Navigate to root folder of the project, where gradlew file is located
cd ..
2- Give executable permissions to gradlew (this needs to be done only once, no need to repeat again)
chmod a+x gradlew
3- Generate debuggable apks of all underlying modules.
./gradlew assembleDebug
You can also generate release apk files for all modules, by using this command instead
./gradlew assembleRelease
for more details, run the following command to see list of all tasks that can be run on gradlew
./gradlew tasks
Note: Running ./gradlew first time might result in terminal downloading the gradle files from server, wait for the downloading to complete before moving forward!
Hope that helps!
Update:
For providing signing information in grade file, Open your module specific build.grade file and update it to contain this code:
signingConfigs {
playstore {
keyAlias 'KEY_ALIS_NAME_HERE'
storeFile file('/PATH_TO_KEYSTORE_FILE_HERE/app.keystore')
keyPassword 'KEY_PASSWORD_HERE'
storePassword 'STORE_PASSWORD_HERE'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-file.txt'
proguardFile 'proguard-file.txt'
debuggable false
signingConfig signingConfigs.playstore
}
}
After that you can simply run ./gradlew assembleRelease to do the work :)

Android Studio: run/debug release version of app

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.

Categories

Resources