bytedeco / javacpp-presets

The missing Java distribution of native C++ libraries
Other
2.68k stars 744 forks source link

InvalidBundleException: File uses reserved file or directory name 'lib'. #1438

Open Martmists-GH opened 1 year ago

Martmists-GH commented 1 year ago

When trying to target android with ffmpeg, I get the following error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':packageDebugBundle'.
    at ...
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.PackageBundleTask$BundleToolWorkAction
    at ...
Caused by: com.android.tools.build.bundletool.model.exceptions.InvalidBundleException: File 'root/lib/arm64-v8a/ffmpeg' uses reserved file or directory name 'lib'.

build.gradle.kts:

import org.jetbrains.compose.ComposeBuildConfig.composeVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("multiplatform")
    id("com.android.application")
    id("org.jetbrains.compose")
    id("com.github.ben-manes.versions")
}

repositories {
    mavenCentral()
    google()
    gradlePluginPortal()
}

kotlin {
    androidTarget()
    jvm("desktop")

    sourceSets {
        commonMain {
            dependencies {
                implementation(compose.ui)
                implementation(compose.animation)
                implementation(compose.foundation)
                implementation(compose.material3)
                implementation(compose.runtime)
                implementation(compose.uiTooling) {
                    exclude("org.jetbrains.compose.material", "material")
                }

                implementation("com.github.skydoves:orbital:${Versions.orbital}")

                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}")

                implementation("io.ktor:ktor-client-core:${Versions.ktor}")
                implementation("io.ktor:ktor-serialization-kotlinx-json:${Versions.ktor}")
                implementation("org.bytedeco:ffmpeg:${Versions.ffmpeg}")
            }
        }

        androidMain {
            dependencies {
                implementation("androidx.activity:activity-compose:${Versions.activityCompose}")

                // TODO: Figure out how to do a split APK with this?
                runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:android-arm")
                runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:android-arm64")
                runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:android-x86")
                runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:android-x86_64")
            }
        }

        val desktopMain by getting {
            dependencies {
                runtimeOnly(compose.desktop.currentOs)

                when (compose.desktop.currentOs) {
                    "org.jetbrains.compose.desktop:desktop-jvm-linux-x64:${Versions.compose}" -> {
                        runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:linux-x86_64")
                    }
                    "org.jetbrains.compose.desktop:desktop-jvm-macos-x64:${Versions.compose}" -> {
                        runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:macosx-x86_64")
                    }
                    "org.jetbrains.compose.desktop:desktop-jvm-windows-x64:${Versions.compose}" -> {
                        runtimeOnly("org.bytedeco:ffmpeg:${Versions.ffmpeg}:windows-x86_64")
                    }
                }
            }
        }
    }
}

android {
    compileSdk = 34
    namespace = "org.mewsic.app"
    ndkVersion = "21.4.7075529"

    defaultConfig {
        applicationId = "org.mewsic.app"
        minSdk = 23
        targetSdk = 34
        versionCode = 0x000001
        versionName = versionCode!!.toString(16).padStart(6, '0').chunked(2).joinToString(".")
    }

    signingConfigs {
        create("release") {
            storeFile = file(System.getenv("KEYSTORE_FILE") ?: "keystore.jks")
            storePassword = System.getenv("KEYSTORE_PASSWORD")
            keyAlias = System.getenv("KEY_ALIAS")
            keyPassword = System.getenv("KEY_PASSWORD")
        }
    }

    lint {
        disable += "AccidentalOctal"
    }

    compileOptions {
        sourceCompatibility = Versions.jvmTarget
        targetCompatibility = Versions.jvmTarget
    }

    composeOptions {
        kotlinCompilerExtensionVersion = composeVersion
    }
}

compose.desktop {
    application {
        mainClass = "org.mewsic.app.MainKt"
    }
}

tasks {
    withType<JavaCompile> {
        sourceCompatibility = Versions.jvmTarget.toString()
        targetCompatibility = Versions.jvmTarget.toString()
    }

    withType<KotlinCompile> {
        kotlinOptions {
            jvmTarget = Versions.jvmTarget.toString()
        }
    }
}
saudet commented 1 year ago

Please follow the instructions here: https://github.com/bytedeco/gradle-javacpp#the-platform-plugin

Martmists-GH commented 1 year ago

Unfortunately that solution does not cover kotlin build scripts. Additionally, the kotlin multiplatform plugin is unable to use custom configurations (such as javacpp) even if they are defined.