bytedeco / gradle-javacpp

Gradle plugins to automate the build process of JavaCPP and JavaCV
Other
56 stars 20 forks source link

android example #5

Closed xuhuan closed 3 years ago

xuhuan commented 4 years ago

hi~ Is there an example of Android?

saudet commented 4 years ago

There are a few (a bit outdated) sample projects here: https://github.com/bytedeco/sample-projects

xuhuan commented 4 years ago

There a few (a bit outdated) sample projects here: https://github.com/bytedeco/sample-projects

Thank you for your reply. None of them are used by this plug-in. I don't know C + +. At present, there are too few documents, so it's not easy for beginners to get started and use.I've been struggling for nearly a week. I've tried all the available documents and examples, but I still don't know how to use it.I use this on Android.

saudet commented 4 years ago

It's not any different with Android. Start from an empty project, and add the plugin as per these instructions: https://github.com/bytedeco/gradle-javacpp#the-platform-plugin

saudet commented 4 years ago

In any case, please let me know the error message that you're getting and I should be able to help!

xuhuan commented 4 years ago

In any case, please let me know the error message that you're getting and I should be able to help!

Thank you very much~

Have you ever tried to compile with Android studio? Android studio is generated by default build.gradle as follows

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Add plugin as follows

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
plugins {
    id 'java-library'
    id 'org.bytedeco.gradle-javacpp-build' version '1.5.4'
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And then it was wrong

Cannot add task 'clean' as a task with that name already exists.

If delete task clean, it will not report an error。

when run task 'javacppJar'

> Task :javacppBuildCommand
> Task :javacppCompileJava NO-SOURCE
> Task :javacppBuildParser FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':javacppBuildParser'.
> java.io.IOException: The process cannot access the file because another process has locked a portion of the file

plugins {} block can only be written in the root build.gradle,then the following parameters cannot be put in the module of app build.gradle

javacppBuildCommand {
}

javacppBuildParser {
}

javacppBuildCompiler {
}

image

IDE environment: Android Studio:4.0.1 JDK:jdk1.8.0_121 NDK:21.3.6528147 Android Gradle Plugin Version:4.0.1 Gradle Version:6.6.1

saudet commented 4 years ago

Ah, you'd like to use the build plugin for Android. I'll update the sample for zlib with builds for Android.

Since Android Studio is not available for other platforms than Android, the build plugin wasn't made to run within it, but it's still probably possible to make it run as part of its build process without too much trouble. Someone will need to figure it out though.

saudet commented 4 years ago

Ok, I've updated the zlib sample in commit https://github.com/bytedeco/gradle-javacpp/commit/3939b5d8caa26e93b07b563dda08e6ce87e3474c. It builds fine on the command line this way:

$ git clone https://github.com/bytedeco/gradle-javacpp
$ cd gradle-javacpp/samples/zlib
$ gradle clean build -PjavacppPlatform=android-arm
$ gradle clean build -PjavacppPlatform=android-arm64
$ gradle clean build -PjavacppPlatform=android-x86
$ gradle clean build -PjavacppPlatform=android-x86_64
xuhuan commented 4 years ago

Ok, I've updated the zlib sample in commit 3939b5d. It builds fine on the command line this way:

$ git clone https://github.com/bytedeco/gradle-javacpp
$ cd gradle-javacpp/samples/zlib
$ gradle clean build -PjavacppPlatform=android-arm
$ gradle clean build -PjavacppPlatform=android-arm64
$ gradle clean build -PjavacppPlatform=android-x86
$ gradle clean build -PjavacppPlatform=android-x86_64

Thank you very much. This example can be run directly in Android studio. I will continue to try to apply the tool in Android studio and will continue to give feedback if there are any problems.

saudet commented 3 years ago

BTW, would you be able to release some sample project for others? There seems to be great demand for one:

saudet commented 3 years ago

Thanks to @iuliuh, we now have this new sample project: https://github.com/bytedeco/sample-projects/tree/master/gradle-javacpp-android Along with instructions for integration with Android Studio. Enjoy!

Michaelzhouisnotwhite commented 4 months ago

Thanks to @iuliuh, we now have this new sample project: https://github.com/bytedeco/sample-projects/tree/master/gradle-javacpp-android Along with instructions for integration with Android Studio. Enjoy!

I build the sample-project: gradle-javacpp-android. But there is no jnijavacpp.cpp jniNativeLibrary.cpp . I can I fix it?

image