tauri-docs icon indicating copy to clipboard operation
tauri-docs copied to clipboard

Create android code signing guide

Open DIMFLIX opened this issue 2 years ago • 12 comments

📋 Page(s) affected (or suggested, for new content)

https://beta.tauri.app/guides/build/

📋 Description or bullet point outline (if proposing new content)

The application is assembled. I am trying to install .apk on my phone, but this error occurs pnpm Vanilla JavaScript

The APK failed to install. Error: INSTALL_PARSE_FAILED_NO_CERTIFICATES: Failed to collect certificates from /data/app/vdml780192954.tmp/base.apk: Attempt to get length of null array

DIMFLIX avatar Nov 11 '23 16:11 DIMFLIX

You can only install signed apks. We don't have a guide for that yet but typically recommend flutter's guide since it's fairly close https://docs.flutter.dev/deployment/android#signing-the-app

FabianLars avatar Nov 18 '23 11:11 FabianLars

For people that have the same question, here is a link to the beta guide with the apk sign process:

https://next--tauri.netlify.app/next/guides/distribution/sign-android/

I tried it on my project and it worked. The flutter guide did give a similar outline, but given that flutter works with build.gradle and tauri works with build.gradle.kts, a code slightly different was required.

AdrianVispalia avatar Jan 17 '24 16:01 AdrianVispalia

For people that have the same question, here is a link to the beta guide with the apk sign process:

https://next--tauri.netlify.app/next/guides/distribution/sign-android/

I tried it on my project and it worked. The flutter guide did give a similar outline, but given that flutter works with build.gradle and tauri works with build.gradle.kts, a code slightly different was required.

Site Not Found

cleveng avatar May 16 '24 11:05 cleveng

For people that have the same question, here is a link to the beta guide with the apk sign process: https://next--tauri.netlify.app/next/guides/distribution/sign-android/ I tried it on my project and it worked. The flutter guide did give a similar outline, but given that flutter works with build.gradle and tauri works with build.gradle.kts, a code slightly different was required.

Site Not Found

I do not remember everything that was mentioned on that website, but I followed some steps on a project and I have:

  • created the file key.properties on /src-tauri/gen/android with the contents (change content):
storePassword=...
keyPassword=...
keyAlias=...
storeFile=storeFile.jks
  • created the file storeFile.jks following Flutter's guide and put it on /src-tauri/gen/android/app :
keytool -genkey -v -keystore ~/storeFile.jks -keyalg RSA \
        -keysize 2048 -validity 10000 -alias upload
  • modified the file build.gradle.kts on /src-tauri/gen/android/app to include the following:
val keyPropertiesFile = rootProject.file("key.properties")
val keyProperties = Properties()
keyProperties.load(FileInputStream(keyPropertiesFile))

android {
    compileSdk = 33
    namespace = "com.tauri.app"
    defaultConfig {
        manifestPlaceholders["usesCleartextTraffic"] = "false"
        applicationId = "com.tauri.app"
        minSdk = 24
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"
    }
    signingConfigs {
        create("release") {
            keyAlias = keyProperties["keyAlias"] as String
            keyPassword = keyProperties["keyPassword"] as String
            storeFile = file(keyProperties["storeFile"] as String)
            storePassword = keyProperties["storePassword"] as String
        }
    }
    buildTypes {
        getByName("debug") {
            manifestPlaceholders["usesCleartextTraffic"] = "true"
            isDebuggable = true
            isJniDebuggable = true
            isMinifyEnabled = false
            packaging {                jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so")
                jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so")
                jniLibs.keepDebugSymbols.add("*/x86/*.so")
                jniLibs.keepDebugSymbols.add("*/x86_64/*.so")
            }
        }
        getByName("release") {
            isMinifyEnabled = true
            // new
            //minifyEnabled = true
            //shrinkResources = true
            //proguardFiles(getDefaultProguardFile('proguard-android.txt'), "proguard-rules.pro")
            isShrinkResources = true

            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )

            // old
            signingConfig = signingConfigs.getByName("release")
            proguardFiles(
                *fileTree(".") { include("**/*.pro") }
                    .plus(getDefaultProguardFile("proguard-android-optimize.txt"))
                    .toList().toTypedArray()
            )
        }
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

I hope this helps! :+1:

AdrianVispalia avatar May 25 '24 15:05 AdrianVispalia

tks.

cleveng avatar May 27 '24 01:05 cleveng

For people that have the same question, here is a link to the beta guide with the apk sign process: https://next--tauri.netlify.app/next/guides/distribution/sign-android/ I tried it on my project and it worked. The flutter guide did give a similar outline, but given that flutter works with build.gradle and tauri works with build.gradle.kts, a code slightly different was required.

Site Not Found

I do not remember everything that was mentioned on that website, but I followed some steps on a project and I have:

  • created the file key.properties on /src-tauri/gen/android with the contents (change content):
storePassword=...
keyPassword=...
keyAlias=...
storeFile=storeFile.jks
  • created the file storeFile.jks following Flutter's guide and put it on /src-tauri/gen/android/app :
keytool -genkey -v -keystore ~/storeFile.jks -keyalg RSA \
        -keysize 2048 -validity 10000 -alias upload
  • modified the file build.gradle.kts on /src-tauri/gen/android/app to include the following:
val keyPropertiesFile = rootProject.file("key.properties")
val keyProperties = Properties()
keyProperties.load(FileInputStream(keyPropertiesFile))

android {
    compileSdk = 33
    namespace = "com.tauri.app"
    defaultConfig {
        manifestPlaceholders["usesCleartextTraffic"] = "false"
        applicationId = "com.tauri.app"
        minSdk = 24
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"
    }
    signingConfigs {
        create("release") {
            keyAlias = keyProperties["keyAlias"] as String
            keyPassword = keyProperties["keyPassword"] as String
            storeFile = file(keyProperties["storeFile"] as String)
            storePassword = keyProperties["storePassword"] as String
        }
    }
    buildTypes {
        getByName("debug") {
            manifestPlaceholders["usesCleartextTraffic"] = "true"
            isDebuggable = true
            isJniDebuggable = true
            isMinifyEnabled = false
            packaging {                jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so")
                jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so")
                jniLibs.keepDebugSymbols.add("*/x86/*.so")
                jniLibs.keepDebugSymbols.add("*/x86_64/*.so")
            }
        }
        getByName("release") {
            isMinifyEnabled = true
            // new
            //minifyEnabled = true
            //shrinkResources = true
            //proguardFiles(getDefaultProguardFile('proguard-android.txt'), "proguard-rules.pro")
            isShrinkResources = true

            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )

            // old
            signingConfig = signingConfigs.getByName("release")
            proguardFiles(
                *fileTree(".") { include("**/*.pro") }
                    .plus(getDefaultProguardFile("proguard-android-optimize.txt"))
                    .toList().toTypedArray()
            )
        }
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

I hope this helps! 👍

How did you config mobile app icon, I Modify the icons and run bun run tauri android build command then then app icon is likes the tauri png.

cleveng avatar May 27 '24 03:05 cleveng

For people that have the same question, here is a link to the beta guide with the apk sign process: https://next--tauri.netlify.app/next/guides/distribution/sign-android/ I tried it on my project and it worked. The flutter guide did give a similar outline, but given that flutter works with build.gradle and tauri works with build.gradle.kts, a code slightly different was required.

Site Not Found

I do not remember everything that was mentioned on that website, but I followed some steps on a project and I have:

  • created the file key.properties on /src-tauri/gen/android with the contents (change content):
storePassword=...
keyPassword=...
keyAlias=...
storeFile=storeFile.jks
  • created the file storeFile.jks following Flutter's guide and put it on /src-tauri/gen/android/app :
keytool -genkey -v -keystore ~/storeFile.jks -keyalg RSA \
        -keysize 2048 -validity 10000 -alias upload
  • modified the file build.gradle.kts on /src-tauri/gen/android/app to include the following:
val keyPropertiesFile = rootProject.file("key.properties")
val keyProperties = Properties()
keyProperties.load(FileInputStream(keyPropertiesFile))

android {
    compileSdk = 33
    namespace = "com.tauri.app"
    defaultConfig {
        manifestPlaceholders["usesCleartextTraffic"] = "false"
        applicationId = "com.tauri.app"
        minSdk = 24
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"
    }
    signingConfigs {
        create("release") {
            keyAlias = keyProperties["keyAlias"] as String
            keyPassword = keyProperties["keyPassword"] as String
            storeFile = file(keyProperties["storeFile"] as String)
            storePassword = keyProperties["storePassword"] as String
        }
    }
    buildTypes {
        getByName("debug") {
            manifestPlaceholders["usesCleartextTraffic"] = "true"
            isDebuggable = true
            isJniDebuggable = true
            isMinifyEnabled = false
            packaging {                jniLibs.keepDebugSymbols.add("*/arm64-v8a/*.so")
                jniLibs.keepDebugSymbols.add("*/armeabi-v7a/*.so")
                jniLibs.keepDebugSymbols.add("*/x86/*.so")
                jniLibs.keepDebugSymbols.add("*/x86_64/*.so")
            }
        }
        getByName("release") {
            isMinifyEnabled = true
            // new
            //minifyEnabled = true
            //shrinkResources = true
            //proguardFiles(getDefaultProguardFile('proguard-android.txt'), "proguard-rules.pro")
            isShrinkResources = true

            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )

            // old
            signingConfig = signingConfigs.getByName("release")
            proguardFiles(
                *fileTree(".") { include("**/*.pro") }
                    .plus(getDefaultProguardFile("proguard-android-optimize.txt"))
                    .toList().toTypedArray()
            )
        }
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

I hope this helps! 👍

new version: tauri-cli v2.0.0-beta.19 build.gradle.kts load new file tauri.properties, you can upgrade

cleveng avatar May 29 '24 07:05 cleveng

How did you config mobile app icon, I Modify the icons and run bun run tauri android build command then then app icon is likes the tauri png.

On src-tauri/tauri.conf.json. On "tauri":

      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/[email protected]",
        "icons/icon.icns",
        "icons/icon.ico"
      ],

On src-tauri/icon I changed every image listed with my own (with the same resolution as the name implies, 32x32.png is a png of 32x32 pixels). For the .icns and .ico I used an online converter tool.

AdrianVispalia avatar May 30 '24 21:05 AdrianVispalia

You can only install signed apks. We don't have a guide for that yet but typically recommend flutter's guide since it's fairly close https://docs.flutter.dev/deployment/android#signing-the-app

That link is broken but the page is available on the wayback machine; https://web.archive.org/web/20240222072319/https://next--tauri.netlify.app/next/guides/distribution/sign-android/

WillsterJohnson avatar Jun 23 '24 12:06 WillsterJohnson

How did you config mobile app icon, I Modify the icons and run bun run tauri android build command then then app icon is likes the tauri png.

Hey, good news. So these last days I had more time available to continue testing my tauri app. I did find the same issue, even though I had replaced all the icon files & configuration (with proper resolution & stuff), the Android app icon was the Tauri icon. So, apart from changing all of what I mentioned before, you also have to do this:

  • Build the Android bundle 1 time: yarn tauri android build
  • Replace the files ic_launcher_foreground.png, ic_launcher.png, ic_launcher_round.png on these folders (in each folder, each file has a different resolution, you have to convert your original icon to the corresponding resolution of the file in the folder you are replacing it):
project/src-tauri/gen/android/app/src/res/mipmap-mdpi
project/src-tauri/gen/android/app/src/res/mipmap-hdpi
project/src-tauri/gen/android/app/src/res/mipmap-xhdpi
project/src-tauri/gen/android/app/src/res/mipmap-xxhdpi
project/src-tauri/gen/android/app/src/res/mipmap-xxxhdpi
  • Build the Android bundle another time: yarn tauri android build

You can check it inside the generated aab file (project/src-tauri/gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab), open it as a zip file and look to the files inside base/res/mipmap-hdpi-v4/ (similar folder structure as before).

AdrianVispalia avatar Jun 27 '24 13:06 AdrianVispalia

How did you config mobile app icon, I Modify the icons and run bun run tauri android build command then then app icon is likes the tauri png.

Hey, good news. So these last days I had more time available to continue testing my tauri app. I did find the same issue, even though I had replaced all the icon files & configuration (with proper resolution & stuff), the Android app icon was the Tauri icon. So, apart from changing all of what I mentioned before, you also have to do this:

  • Build the Android bundle 1 time: yarn tauri android build
  • Replace the files ic_launcher_foreground.png, ic_launcher.png, ic_launcher_round.png on these folders (in each folder, each file has a different resolution, you have to convert your original icon to the corresponding resolution of the file in the folder you are replacing it):
project/src-tauri/gen/android/app/src/res/mipmap-mdpi
project/src-tauri/gen/android/app/src/res/mipmap-hdpi
project/src-tauri/gen/android/app/src/res/mipmap-xhdpi
project/src-tauri/gen/android/app/src/res/mipmap-xxhdpi
project/src-tauri/gen/android/app/src/res/mipmap-xxxhdpi
  • Build the Android bundle another time: yarn tauri android build

You can check it inside the generated aab file (project/src-tauri/gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab), open it as a zip file and look to the files inside base/res/mipmap-hdpi-v4/ (similar folder structure as before).

SRC_ICON=./src-tauri/icons/android.png
DIR_RES=./src-tauri/gen/android/app/src/main/res/

.PHONY: icons
# generate mobile icons
icons:
	mkdir -p {mipmap-hdpi,mipmap-mdpi,mipmap-xhdpi,mipmap-xxhdpi,mipmap-xxxhdpi}
	sips -z 162 162     $(SRC_ICON) --out mipmap-hdpi/ic_launcher_foreground.png
	sips -z 49 49     $(SRC_ICON) --out mipmap-hdpi/ic_launcher_round.png
	sips -z 49 49     $(SRC_ICON) --out mipmap-hdpi/ic_launcher.png
	sips -z 108 108     $(SRC_ICON) --out mipmap-mdpi/ic_launcher_foreground.png
	sips -z 48 48     $(SRC_ICON) --out mipmap-mdpi/ic_launcher_round.png
	sips -z 49 49     $(SRC_ICON) --out mipmap-mdpi/ic_launcher.png
	sips -z 216 216     $(SRC_ICON) --out mipmap-xhdpi/ic_launcher_foreground.png
	sips -z 96 96     $(SRC_ICON) --out mipmap-xhdpi/ic_launcher_round.png
	sips -z 96 96     $(SRC_ICON) --out mipmap-xhdpi/ic_launcher.png
	sips -z 324 324     $(SRC_ICON) --out mipmap-xxhdpi/ic_launcher_foreground.png
	sips -z 144 144     $(SRC_ICON) --out mipmap-xxhdpi/ic_launcher_round.png
	sips -z 144 144     $(SRC_ICON) --out mipmap-xxhdpi/ic_launcher.png
	sips -z 432 432     $(SRC_ICON) --out mipmap-xxxhdpi/ic_launcher_foreground.png
	sips -z 192 192     $(SRC_ICON) --out mipmap-xxxhdpi/ic_launcher_round.png
	sips -z 144 144     $(SRC_ICON) --out mipmap-xxxhdpi/ic_launcher.png
	mv -v -f mipmap-hdpi/* $(DIR_RES)/mipmap-hdpi/
	mv -v -f mipmap-mdpi/* $(DIR_RES)/mipmap-mdpi/
	mv -v -f mipmap-xhdpi/* $(DIR_RES)/mipmap-xhdpi/
	mv -v -f mipmap-xxhdpi/* $(DIR_RES)/mipmap-xxhdpi/
	mv -v -f mipmap-xxxhdpi/* $(DIR_RES)/mipmap-xxxhdpi/
	rm -rf mipmap-hdpi mipmap-mdpi mipmap-xhdpi mipmap-xxhdpi mipmap-xxxhdpi

the file of MakeFile. Waiting for you to a better solution

cleveng avatar Jul 01 '24 09:07 cleveng

How did you config mobile app icon, I Modify the icons and run bun run tauri android build command then then app icon is likes the tauri png.

Hey, good news. So these last days I had more time available to continue testing my tauri app. I did find the same issue, even though I had replaced all the icon files & configuration (with proper resolution & stuff), the Android app icon was the Tauri icon. So, apart from changing all of what I mentioned before, you also have to do this:

  • Build the Android bundle 1 time: yarn tauri android build
  • Replace the files ic_launcher_foreground.png, ic_launcher.png, ic_launcher_round.png on these folders (in each folder, each file has a different resolution, you have to convert your original icon to the corresponding resolution of the file in the folder you are replacing it):
project/src-tauri/gen/android/app/src/res/mipmap-mdpi
project/src-tauri/gen/android/app/src/res/mipmap-hdpi
project/src-tauri/gen/android/app/src/res/mipmap-xhdpi
project/src-tauri/gen/android/app/src/res/mipmap-xxhdpi
project/src-tauri/gen/android/app/src/res/mipmap-xxxhdpi
  • Build the Android bundle another time: yarn tauri android build

You can check it inside the generated aab file (project/src-tauri/gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab), open it as a zip file and look to the files inside base/res/mipmap-hdpi-v4/ (similar folder structure as before).

SRC_ICON=./src-tauri/icons/android.png
DIR_RES=./src-tauri/gen/android/app/src/main/res/

.PHONY: icons
# generate mobile icons
icons:
	mkdir -p {mipmap-hdpi,mipmap-mdpi,mipmap-xhdpi,mipmap-xxhdpi,mipmap-xxxhdpi}
	sips -z 162 162     $(SRC_ICON) --out mipmap-hdpi/ic_launcher_foreground.png
	sips -z 49 49     $(SRC_ICON) --out mipmap-hdpi/ic_launcher_round.png
	sips -z 49 49     $(SRC_ICON) --out mipmap-hdpi/ic_launcher.png
	sips -z 108 108     $(SRC_ICON) --out mipmap-mdpi/ic_launcher_foreground.png
	sips -z 48 48     $(SRC_ICON) --out mipmap-mdpi/ic_launcher_round.png
	sips -z 49 49     $(SRC_ICON) --out mipmap-mdpi/ic_launcher.png
	sips -z 216 216     $(SRC_ICON) --out mipmap-xhdpi/ic_launcher_foreground.png
	sips -z 96 96     $(SRC_ICON) --out mipmap-xhdpi/ic_launcher_round.png
	sips -z 96 96     $(SRC_ICON) --out mipmap-xhdpi/ic_launcher.png
	sips -z 324 324     $(SRC_ICON) --out mipmap-xxhdpi/ic_launcher_foreground.png
	sips -z 144 144     $(SRC_ICON) --out mipmap-xxhdpi/ic_launcher_round.png
	sips -z 144 144     $(SRC_ICON) --out mipmap-xxhdpi/ic_launcher.png
	sips -z 432 432     $(SRC_ICON) --out mipmap-xxxhdpi/ic_launcher_foreground.png
	sips -z 192 192     $(SRC_ICON) --out mipmap-xxxhdpi/ic_launcher_round.png
	sips -z 144 144     $(SRC_ICON) --out mipmap-xxxhdpi/ic_launcher.png
	mv -v -f mipmap-hdpi/* $(DIR_RES)/mipmap-hdpi/
	mv -v -f mipmap-mdpi/* $(DIR_RES)/mipmap-mdpi/
	mv -v -f mipmap-xhdpi/* $(DIR_RES)/mipmap-xhdpi/
	mv -v -f mipmap-xxhdpi/* $(DIR_RES)/mipmap-xxhdpi/
	mv -v -f mipmap-xxxhdpi/* $(DIR_RES)/mipmap-xxxhdpi/
	rm -rf mipmap-hdpi mipmap-mdpi mipmap-xhdpi mipmap-xxhdpi mipmap-xxxhdpi

the file of MakeFile. Waiting for you to a better solution

I think to solve this problem you should create a new issue. Here we solve the application signing issue.

DIMFLIX avatar Jul 01 '24 09:07 DIMFLIX