Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we have to specify the platform property on Android? #687

Closed
lancewoo opened this issue Jun 5, 2023 · 6 comments
Closed

Do we have to specify the platform property on Android? #687

lancewoo opened this issue Jun 5, 2023 · 6 comments
Labels

Comments

@lancewoo
Copy link

lancewoo commented Jun 5, 2023

For Android apks, some may only inlcude armeabi-v7a libraries but they want to run on an arm64-v8 device. If we don't set the javacpp.platform, it seems those apps won't run properly.

@saudet
Copy link
Member

saudet commented Jun 5, 2023

No, we don't need to, for example: https://github.com/bytedeco/sample-projects/blob/master/JavaCV-android-example/app/build.gradle

@lancewoo
Copy link
Author

lancewoo commented Jun 6, 2023

Great! Then I only used an ndk abifilters block to filter out those unwanted, like this:

        ndk {
            // in case you want to use some arch only
            abiFilters "armeabi-v7a"//, "arm64-v8a"
        }

There's another question here. How can I package the executables like ffmpeg and ffprobe into the apk? Any other tricks?

@saudet
Copy link
Member

saudet commented Jun 6, 2023

There's another question here. How can I package the executables like ffmpeg and ffprobe into the apk? Any other tricks?

We need to use Android API 28 or less for that to work, see bytedeco/javacv#1127 (comment)

@saudet saudet added the question label Jun 6, 2023
@saudet saudet closed this as completed Jun 6, 2023
@lancewoo
Copy link
Author

lancewoo commented Jun 7, 2023

Hi @saudet , the problem here is ffmpeg didn't get packaged. Even though I changed targetSdkVersion to 26(Android 8.0), I find that the ffmpeg executable is still missing in the final apk. So I am wondering why the executable didn't get packaged.

But when I compiled the app using the dependency jar file directly, the executable file is right there in the apk. It seems different.

@saudet
Copy link
Member

saudet commented Jun 7, 2023

The Android plugin won't do that for us, you'll need to add them as resources somehow. Probably copying them in the right subdirectory for Gradle to pick them up should do the trick.

@lancewoo
Copy link
Author

lancewoo commented Jun 7, 2023

OK, got it. Thanks! @saudet

Then I am posting my workaround code snippet here for somebody else's information:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 24
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters "armeabi-v7a"//, "arm64-v8a"
        }
    }
   
....
    packagingOptions {
        pickFirst 'META-INF/native-image/android-arm*/jnijavacpp/jni-config.json'
        pickFirst 'META-INF/native-image/android-arm*/jnijavacpp/reflect-config.json'
    }

   ....
}

dependencies {
//    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // java
    implementation 'org.bytedeco:javacpp:1.5.9'
    implementation 'org.bytedeco:ffmpeg:6.0-1.5.9'
    // so
    implementation files("libs/javacpp-1.5.9-android-arm.jar",
            "libs/ffmpeg-6.0-1.5.9-android-arm.jar"
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants