tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.36k stars 2.58k forks source link

[bug] android code signin guide is wrong #11739

Open raisfeld-ori opened 2 days ago

raisfeld-ori commented 2 days ago

Describe the bug

I want to build and deploy my android app, but when I ran the code I got an error: "App Not Installed As Package Appears To Be Invalid"

I thought this was because of the fact that the app was unsigned, so I started to follow the android signin guide but when building the app now I got a new error in the build.gradle.kts on line 34: "Malformed \uxxxx encoding."

Reproduction

this is a standard tauri app, made using npm create tauri@latest (with vite in the frontend) with no extra packages, only the shell plugin and the notification plugin being used.

I also followed the guide and create keystore.properties in the android directory:

password=(here is my Alias password)
keyAlias=upload
storeFile=(here is my absulote path to the jks file)

I also changed the build.gradle.kts according to the guide:

import java.util.Properties
import java.io.FileInputStream
plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("rust")
}

val tauriProperties = Properties().apply {
    val propFile = file("tauri.properties")
    if (propFile.exists()) {
        propFile.inputStream().use { load(it) }
    }
}

android {
    compileSdk = 34
    namespace = "com.israir.app"
    defaultConfig {
        manifestPlaceholders["usesCleartextTraffic"] = "false"
        applicationId = "com.israir.app"
        minSdk = 24
        targetSdk = 34
        versionCode = tauriProperties.getProperty("tauri.android.versionCode", "1").toInt()
        versionName = tauriProperties.getProperty("tauri.android.versionName", "1.0")
    }
    signingConfigs {
    create("release") {
        val keystorePropertiesFile = rootProject.file("keystore.properties")
        val keystoreProperties = Properties()
        if (keystorePropertiesFile.exists()) {
            keystoreProperties.load(FileInputStream(keystorePropertiesFile))
        }

        keyAlias = keystoreProperties["keyAlias"] as String
        keyPassword = keystoreProperties["password"] as String
        storeFile = file(keystoreProperties["storeFile"] as String)
        storePassword = keystoreProperties["password"] 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") {
            signingConfig = signingConfigs.getByName("release")
            isMinifyEnabled = true

            proguardFiles(
                *fileTree(".") { include("**/*.pro") }
                    .plus(getDefaultProguardFile("proguard-android-optimize.txt"))
                    .toList().toTypedArray()
            )
        }
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        buildConfig = true
    }
}

rust {
    rootDirRel = "../../../"
}

dependencies {
    implementation("androidx.webkit:webkit:1.6.1")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.8.0")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.4")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
}

apply(from = "tauri.build.gradle.kts")

also, I tested and it seems gradle does find my jks file, but fails to read it (also, the password is 100% accurate, since I deleted the old jks file and created a new one).

Expected behavior

I just want to compile the app and deliver it to the client ):

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 x86_64 (X64)
    ✔ WebView2: 130.0.2849.80
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-gnu (default)
    - node: 20.9.0
    - pnpm: 9.4.0
    - yarn: 1.22.22
    - npm: 10.8.3
    - bun: 1.1.2
    - deno: deno 2.0.6

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.0
    - tao 🦀: 0.30.8
    - tauri-cli 🦀: 1.5.6
    - @tauri-apps/api : 2.1.1
    - @tauri-apps/cli : 2.1.0

[-] Plugins
    - tauri-plugin-notification 🦀: 2.0.1
    - @tauri-apps/plugin-notification : 2.0.0
    - tauri-plugin-shell 🦀: 2.0.2
    - @tauri-apps/plugin-shell : 2.0.1

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

> israir@0.1.0 build
> tsc && vite build

vite v5.4.11 building for production...
✓ 1945 modules transformed.
dist/index.html                   0.49 kB │ gzip:   0.31 kB
dist/assets/index-D-dDrWGl.css   21.52 kB │ gzip:   4.47 kB
dist/assets/index-Bg0t2eB_.js   829.82 kB │ gzip: 223.29 kB

(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 29.00s
   Compiling israir v0.1.0 (C:\Users\raisf\Desktop\projects\Israir\src-tauri)
    Finished `release` profile [optimized] target(s) in 1m 53s
    Info symlinking lib "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so" in jniLibs dir "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\app/src/main/jniLibs/arm64-v8a"
    Info "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so" requires shared lib "libandroid.so"
    Info "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so" requires shared lib "libdl.so"
    Info "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so" requires shared lib "liblog.so"
    Info "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so" requires shared lib "libm.so"
    Info "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so" requires shared lib "libc.so"
    Info symlink at "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\app/src/main/jniLibs/arm64-v8a\\libisrair_lib.so" points to "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\aarch64-linux-android\\release\\libisrair_lib.so"
    Info symlink at "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\app/src/main/jniLibs/armeabi-v7a\\libisrair_lib.so" points to "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\armv7-linux-androideabi\\release\\libisrair_lib.so"
    Info symlink at "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\app/src/main/jniLibs/x86\\libisrair_lib.so" points to "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\i686-linux-android\\release\\libisrair_lib.so"
    Info symlink at "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\app/src/main/jniLibs/x86_64\\libisrair_lib.so" points to "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\target\\x86_64-linux-android\\release\\libisrair_lib.so"

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\raisf\Desktop\projects\Israir\src-tauri\gen\android\app\build.gradle.kts' line: 32

* What went wrong:
Malformed \uxxxx encoding.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s
Failed to assemble APK: command ["C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\gradlew.bat", "--project-dir", "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android"] exited with code 1: command ["C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\gradlew.bat", "--project-dir", "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android"] exited with code 1
    Error Failed to assemble APK: command ["C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\gradlew.bat", "--project-dir", "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android"] exited with code 1: command ["C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android\\gradlew.bat", "--project-dir", "C:\\Users\\raisf\\Desktop\\projects\\Israir\\src-tauri\\gen/android"] exited with code 1

Additional context

No response

raisfeld-ori commented 2 days ago

Solved it! half of it was my fault, and the other half is still my fault, but I think it should be mentioned in the documentation.

for the first half, I simply copied the path like usual on windows, and accidentally kept the escape characters. this is a fairly easy fix, just replace '\' with '\' and the error disapears.

the second part is the more problematic part, the path. in the docs, it says: "storeFile=<location of the key store file, such as /Users//upload-keystore.jks or C:\Users\\upload-keystore.jks>", looking at "C:\Users\\upload-keystore.jks>", I decided to place my file there.

while debugging the first error, I looked at the path it was reading: 'C:\Users\raisf\Desktop\projects\Israir\src-tauri\gen\android\app\"C:\Users\raisf\upload-keystore.jks"', in no point does the docs mention that the path is relative, and that the keystore should be placed in the app directory.

to simply put it, if you get any error about the keystore properties or jks file, just check the paths and make sure it's correct

FabianLars commented 2 days ago

in no point does the docs mention that the path is relative, and that the keystore should be placed in the app directory.

this doesn't sound intentional. i think we thought absolute paths work, right @lucasfernog ?