Flutter application release is different than debug - android

I have created an app in flutter using Android studio which I want to deploy.
Flutter version is 2.10.
Dart version is 2.16.0.
When I run or debug main.dart from Android studio everything works as expected.
I have signed the application following the instructions from here:
https://docs.flutter.dev/deployment/android
I have created the keystore using the following command:
"C:\Program Files\Android\Android Studio\jre\bin\keytool" -genkey -v -keystore c:\upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Created key.properties file with the following content
storePassword=password from previous step
keyPassword=password from previous step
keyAlias=key
storeFile=location of the key store file, such as /Users/<user name>/upload-keystore.jks
in [project]/android/app/build.gradle added the keystore information before the Android block as follow
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
and replaced
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
}
}
with
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
And after changing the gradle file I ran flutter clean.
After the specified steps the application can still the debugged and can be ran as expected.
I am building a bundle with the following command
flutter build appbundle
The build is successful and I get the output file in
build\app\outputs\bundle\release\app-release.aab
Using bundletool I convert the .aab file to apks and install it on my phone with the following commands:
java -jar "PATH/bundletool-all-1.8.2.jar" build-apks --bundle=PATH/app-release.aab --ks="PATH/upload-keystore.jks" --ks-key-alias=key --output=PATH/app-release.apks
java -jar "PATH/bundletool-all-1.8.2.jar" install-apks --apks=PATH/app-release.apks
where PATH is the path to the directory of the file.
After the app is being installed and launched I get the attached window
which is completely different than the app I wrote.
Can someone please tell me what am I doing wrong?
Best regards,
Stanko

Thanks to Tomas's comment I have found the solution.
Running the following command
flutter run
a different project has been started, so I had to use this instead
flutter run PATH/lib/src/main.dart
which started the correct project, similarly for the app bundle I had to run
flutter build appbundle PATH/lib/src/main.dart
Thank you for your help!
Best wishes,
Stanko

Related

Flutter signed APK blocked by Play Protect

As I get ready to release my first Flutter app on Play Store I am in the process of testing the "release" APK on one of my local devices. To that end I have done the following
On Windows I issued
keytool -genkey -v -keystore path:\to\project\keys\keystore.jks -alias AliasName -keyalg RSA - keysize 2048 -validity 10000
and then proceeded to answer all the questions that were asked. I then created the file
path://to/project/android/key.properties
with the following entries
storePassword=[store password used above]
keyPassword=[key password used above]
keyAlias=[same alias as above]
storeFile=../../keys/keystore.jks
Finally I edited path://to/project/android/app/build.gradle as follows
signingConfigs
{
release
{
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes
{
release
{
signingConfig signingConfigs.release
}
}
With this done from the command line I ran
cls && flutter clean && flutter build apk --release --split-per-abi
and installed the resulting path://to/project/build/outputs/apk/release/app-arm64-v8a-release.apk on my local LG Fit smartphone. On browsing to it and trying to install it I am shown the message
Blocked by Play Protect
Play Protect does not recognize...
It is not clear to me why this is happening. As far as I can tell I have followed the steps correctly and the Flutter build process has not thrown up any problems.

Following Flutter Dev steps for preparing android app causes gradle to fail to install

I am currently working with the flutter ble master pluggin to do some bluetooth testing. I have the example working on my virtual environment just fine. I wanted to publish the app so I followed the instructions on flutter.dev for doing so (https://flutter.dev/docs/deployment/android). I have completed all the steps without issue, however when I go to build an APK file I get the following error:
"* Error running Gradle:
ProcessException: Process "C:\flutter_ble-master\flutter_ble-master\example\android\gradlew.bat" exited abnormally:
Command: C:\flutter_ble-master\flutter_ble-master\example\android\gradlew.bat app:properties
Please review your Gradle project setup in the android/ folder."
I have rolled back the changes I made when following the document and isolated the issue to the second part of the "Configure signing in gradle" step. In this step you perform the following changes:
Replace the following:
content_copy
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
}
}
With the signing configuration info:
content_copy
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
By removing this change I can build an APK and run the app on my phone no problem.
Any idea what I am doing wrong here?
Thanks!

How to fix app not installing compiled apk on my mobile device, using generating signed APK of react-native

I currently new developing android react-native, I have problem regarding deploying my application on other mobile device, I read the documentation of react native How to generate signed APK, i did the instruction of there document
React Native signed-apk-android
I already done configuring those requirements based on there document. I will show you the step that I did.
First: Install this in the cmd
keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
Second: Setting up gradle variables
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=123456
MYAPP_RELEASE_KEY_PASSWORD=123456
Third: Adding signing config to your app's gradle config
...
android {
...
defaultConfig { ... }
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}
...
Lastly: Generating the release APK
Simply run the following in a terminal:
$ cd android
$ ./gradlew assembleRelease
Before I do the installation, I gonna make sure that the package
clearly uninstalled on my mobile device.
Release APK:
Error:
you need to click on the apk (probably with developer mode active press a few times on the build number in the settings menu)

How to sign android apk using jenkins

I have my keystore release.keystore in the path /home/ankit/keystores/release.keystore. I want to use the keypair aliased as example for signing an app that is built using Jenkins. However, I am unable to feed the address of the keystore in the Jenkins. Below is the screenshot:
As it can be seen, there is a drop down list against the key store label and it has no item. I tried to follow the official doc but I didn't get it.
I think I have to link the existing keypair somehow to Jenkins, so that it shows up in the drop down list. But I can't figure how.
Instead you could configure this all in gradle itself, which will work independent of any CI. First create a build.properties in root of your project and include following:
#Key store
keystore.release=../keys/release.keystore
keystore.debug=../keys/debug.keystore
keystore.key.alias=...
keystore.key.password=...
keystore.password=...
Now in your app modules build.gradle access those props:
final Properties props = new Properties()
props.load(new FileInputStream('build.properties'))
android {
signingConfigs {
release {
keyAlias props['keystore.key.alias']
keyPassword props['keystore.key.password']
storeFile file(props['keystore.release'])
storePassword props['keystore.password']
}
debug {
storeFile file(props['keystore.debug'])
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
debug {
...
signingConfig signingConfigs.debug
}
}
}
Now make sure it works in your local machine with ./gradlew clean assembleRelease (There's something else if you do in PC)
After that commit the changes and update the gradle build settings in your CI. And make sure those keystores are there.
From the Android Signing Jenkins Plugin documentation:
Before adding a Sign Android APKs build step to a job, you must configure a certificate credential using the Credentials Plugin's UI.
If you need more details about how to use the Credentials Plugin in Jenkins, here is the user guide.

Android Studio: how to generate signed APK using Gradle?

I've searched on Google and SO but cannot find my answer.
This is the first time I'm working with the Gradle system and I am now at the point of generating a signed APK to upload to Google Play (project is imported from eclipse).
Now, I've read the part here that you should add signingConfigs to your build.gradle.
I've added these lines and now I saw that you need to run ./gradlew assembleRelease but running this in my CMD returns
'gradle' is not recognized as an internal or external command,
operable program or batch file.
I've also tried to right click on the build.gradle and run it, saying it was sucessful but once I look in the build/apk folder only a file called app-debug-unaligned.apk.
So, how do I generate the signed APK using the Gradle system?
There are three ways to generate your build as per the buildType. (In your case, it's release but it can be named anything you want.)
Go to Gradle Task in right panel of Android Studio and search for assembleRelease or assemble(#your_defined_buildtype) under Module Tasks
Go to Build Variant in Left Panel and select the build from drop down
Go to project root directory in File Explore and open cmd/terminal and run:
Linux: ./gradlew assembleRelease or assemble(#your_defined_buildtype)
Windows: gradlew assembleRelease or assemble(#your_defined_buildtype)
If you want to do a release build (only), you can use Build > Generate Signed apk. For other build types, only the above three options are available.
You can find the generated APK in your module/build directory having the build type name in it.
It is possible to take any existing Android Studio gradle project and build/sign it from the command line without editing any files. This makes it very nice for storing your project in version control while keeping your keys and passwords separate:
./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD
You can use this code
android {
...
signingConfigs {
release {
storeFile file("../your_key_store_file.jks")
storePassword "some_password"
keyAlias "alias_name"
keyPassword "key_password"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
...
}
then from your terminal run
./gradlew assembleRelease
you will get the apk at
your-android-app/build/outputs/apk/your-android-app-release.apk
I think this can help you https://www.timroes.de/2013/09/22/handling-signing-configs-with-gradle/ then just select the Release from the Build Variants
If you live in certain countries, be sure to use a VPN.
step1: run this command in the command-line:
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
it will ask you for some information such as password, name,... and enter them.
step2: create a file name key.properties in your android folder.
write these lines in the created file
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=<location of the key store file, such as ~/key.jks>
keep the key.properties file private, always keep a backup of the key.properties file and never publish publicly.
step3: Replace the following lines in app-level Gradle
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
step4:
keytool -list -v -keystore ~/key.jks -alias key -storepass <password> -keypass <password>
step5:
I recommend building APK, using android studio.
Build > Generate Signed Bundle/APK...
This is for Kotlin DSL (build.gradle.kts).
You could either define your properties in local.properties file in the project root directory or define them as environment variables (which is especially useful for CIs like GitHub Actions).
// See https://stackoverflow.com/q/60474010
fun getLocalProperty(key: String) = gradleLocalProperties(rootDir).getProperty(key)
fun String?.toFile() = file(this!!)
// Could also use System.getenv("VARIABLE_NAME") to get each variable individually
val environment: Map<String, String> = System.getenv()
android {
signingConfigs {
create("MyAppSigningConfig") {
keyAlias = getLocalProperty("signing.keyAlias") ?: environment["SIGNING_KEY_ALIAS"] ?: error("Error!")
storeFile = (getLocalProperty("signing.storeFile") ?: environment["SIGNING_STORE_FILE"] ?: error("Error!")).toFile()
keyPassword = getLocalProperty("signing.keyPassword") ?: environment["SIGNING_KEY_PASSWORD"] ?: error("Error!")
storePassword = getLocalProperty("signing.storePassword") ?: environment["SIGNING_STORE_PASSWORD"] ?: error("Error!")
enableV1Signing = true
enableV2Signing = true
}
}
buildTypes {
getByName("release") { // OR simply release { in newer versions of Android Gradle Plugin (AGP)
signingConfig = signingConfigs["MyAppSigningConfig"]
// ...
}
}
}
myProject/local.properties file:
signing.keyAlias=foo
signing.keyPassword=bar
# also called keystore
signing.storePassword=abcdefgh
signing.storeFile=C\:\\my-files\\my-keystore.jks
NOTE: Do NOT add your local.properties file to your version control system (like Git), as it exposes your secret information like passwords etc. to the public (if it's a public repository).
Generate your APK with either of the 3 ways that this answer mentioned.
build menu > generate signed apk

Categories

Resources