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

android example #5

Closed
xuhuan opened this issue Sep 10, 2020 · 11 comments
Closed

android example #5

xuhuan opened this issue Sep 10, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@xuhuan
Copy link

xuhuan commented Sep 10, 2020

hi~ Is there an example of Android?

@saudet
Copy link
Member

saudet commented Sep 10, 2020

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

@saudet saudet added enhancement New feature or request help wanted Extra attention is needed labels Sep 10, 2020
@xuhuan
Copy link
Author

xuhuan commented Sep 10, 2020

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
Copy link
Member

saudet commented Sep 10, 2020

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
Copy link
Member

saudet commented Sep 11, 2020

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

@xuhuan
Copy link
Author

xuhuan commented Sep 11, 2020

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
Copy link
Member

saudet commented Sep 11, 2020

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
Copy link
Member

saudet commented Sep 12, 2020

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

@xuhuan
Copy link
Author

xuhuan commented Sep 14, 2020

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
Copy link
Member

saudet commented Nov 19, 2020

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

@saudet saudet removed the help wanted Extra attention is needed label Nov 27, 2020
@saudet
Copy link
Member

saudet commented Nov 27, 2020

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!

@saudet saudet closed this as completed Nov 27, 2020
@Michaelzhouisnotwhite
Copy link

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

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

No branches or pull requests

3 participants