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

gradle-javacpp-android: update gradle and javacpp version #71

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gradle-javacpp-android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ It was created by following the instructions available at:
Along with the `NativeLibrary.h` example file from:
* https://github.com/bytedeco/javacpp#accessing-native-apis

## Instructions
To generate jni stuffs, run:
```shell
./gradlew :app:javacppCompileJavaDebug && ./gradlew :app:javacppBuildParserDebug && ./gradlew :app:javacppBuildCompilerDebug
```

Then simply press run button in Android Studio.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't that be done from Android Studio??


----
Author: [Samuel Audet](https://github.com/saudet/)
Sponsor: [Iuliu Horga](https://github.com/iuliuh) via [xs:code](https://xscode.com/)
51 changes: 27 additions & 24 deletions gradle-javacpp-android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
plugins {
id 'com.android.application'
id 'org.bytedeco.gradle-javacpp-build' version '1.5.4'
id 'org.bytedeco.gradle-javacpp-build' version '1.5.10'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
namespace "com.example.myapplication"
compileSdk 34
buildToolsVersion = "34.0.0"

defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 16
targetSdkVersion 30
minSdkVersion 19
targetSdkVersion 34
versionCode 1
versionName "1.0"

Expand All @@ -31,32 +32,34 @@ android {
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
version "3.22.1"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

android.applicationVariants.all { variant ->
// For library variant, please use android.libraryVariants.
// (see in plugins if you are using com.android.application or com.android.library)
android.applicationVariants.configureEach { variant ->
def variantName = variant.name.capitalize() // either "Debug" or "Release"
def javaCompile = project.tasks.getByName("compile${variantName}JavaWithJavac")
def generateJson = project.tasks.getByName("generateJsonModel$variantName")
def javaCompile = project.tasks.named("compile${variantName}JavaWithJavac").get()
def generateJson = project.tasks.named("generateJsonModel$variantName").get()

// Compiles NativeLibraryConfig.java
task "javacppCompileJava$variantName"(type: JavaCompile) {
tasks.register("javacppCompileJava$variantName", JavaCompile) {
include 'com/example/myapplication/NativeLibraryConfig.java'
source = javaCompile.source
classpath = javaCompile.classpath
destinationDir = javaCompile.destinationDir
destinationDirectory.set(javaCompile.destinationDirectory)
}

// Parses NativeLibrary.h and outputs NativeLibrary.java
task "javacppBuildParser$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
tasks.register("javacppBuildParser$variantName", org.bytedeco.gradle.javacpp.BuildTask) {
dependsOn "javacppCompileJava$variantName"
classPath = [javaCompile.destinationDir]
classPath = [file(javaCompile.destinationDirectory)]
includePath = ["$projectDir/src/main/cpp/"]
classOrPackageNames = ['com.example.myapplication.NativeLibraryConfig']
outputDirectory = file("$projectDir/src/main/java/")
Expand All @@ -66,9 +69,9 @@ android.applicationVariants.all { variant ->
javaCompile.dependsOn "javacppBuildParser$variantName"

// Generates jnijavacpp.cpp and jniNativeLibrary.cpp
task "javacppBuildCompiler$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
tasks.register("javacppBuildCompiler$variantName", org.bytedeco.gradle.javacpp.BuildTask) {
dependsOn javaCompile
classPath = [javaCompile.destinationDir]
classPath = [file(javaCompile.destinationDirectory)]
classOrPackageNames = ['com.example.myapplication.NativeLibrary']
compile = false
deleteJniFiles = false
Expand All @@ -80,11 +83,11 @@ android.applicationVariants.all { variant ->
}

dependencies {
implementation 'org.bytedeco:javacpp:1.5.4'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.bytedeco:javacpp:1.5.10'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
6 changes: 3 additions & 3 deletions gradle-javacpp-android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand All @@ -9,7 +8,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
10 changes: 5 additions & 5 deletions gradle-javacpp-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "com.android.tools.build:gradle:8.3.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,10 +15,10 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
tasks.register('clean', Delete) {
delete rootProject.layout.buildDirectory
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip