bytedeco / gradle-javacpp

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

Can not generate jnijavacpp.cpp and jniNativeLibrary.cpp #26

Closed binbowang1987 closed 2 years ago

binbowang1987 commented 2 years ago

I am refrencing gradle-javacpp-android to use javacpp with android studio. After a bit adjust to gradle-javacpp-android, it successfully generated NativeLibrary. But jnijavacpp.cpp and jniNativeLibrary.cpp are not generated.

plugins {
    id 'com.android.application'
    id 'org.bytedeco.gradle-javacpp-build' version '1.5.7'
}

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked"
    }
}

android {
    compileSdkVersion 32

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 28
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.18.1"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ndkVersion '25.1.8937393'
    buildToolsVersion '33.0.0'
}

android.applicationVariants.all { 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")

    // Compiles NativeLibraryConfig.java
    task "javacppCompileJava$variantName"(type: JavaCompile) {
        include 'com/example/myapplication/NativeLibraryConfig.java'
        source = javaCompile.source
        classpath = javaCompile.classpath
        destinationDir = javaCompile.destinationDir
        doLast{
            println "Hello World javacppCompileJava"
        }
    }

    // Parses NativeLibrary.h and outputs NativeLibrary.java
    task "javacppBuildParser$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
        dependsOn "javacppCompileJava$variantName"
        classPath = [javaCompile.destinationDir]
        includePath =  ["$projectDir/src/main/cpp/"]
        classOrPackageNames = ['com.example.myapplication.NativeLibraryConfig']
        outputDirectory = file("$projectDir/src/main/java/")
        doLast{
            println "Hello World javacppBuildParser"
        }
    }

    // Compiles NativeLibrary.java and everything else
    javaCompile.dependsOn "javacppBuildParser$variantName"

    // Generates jnijavacpp.cpp and jniNativeLibrary.cpp
    task "javacppBuildCompiler$variantName"(type: org.bytedeco.gradle.javacpp.BuildTask) {
        dependsOn javaCompile
        classPath = [javaCompile.destinationDir]
        classOrPackageNames = ['com.example.myapplication.NativeLibrary']
        compile = true
        deleteJniFiles = false
        outputDirectory = file("$projectDir/src/main/cpp/")
        doLast{
            println "Hello World javacppBuildCompiler"
        }
    }

    // Picks up the C++ files listed in CMakeLists.txt
    generateJson.dependsOn "javacppBuildCompiler$variantName"
}

dependencies {

    implementation 'org.bytedeco:javacpp:1.5.7'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
binbowang1987 commented 2 years ago

By reviewing the build log, it looks like task javacppBuildCompiler$variantName is not executed. I don't know why, please help me, thank you.

Executing tasks: [:app:assembleDebug] in project E:\develop\android\sample-projects\gradle-javacpp-android

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:checkDebugAarMetadata UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugMainManifest UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugManifestForPackage UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE

> Task :app:javacppCompileJavaDebug
Hello World javacppCompileJava

> Task :app:javacppBuildParserDebug
Hello World javacppBuildParser

> Task :app:compileDebugJavaWithJavac
E:\develop\android\sample-projects\gradle-javacpp-android\app\src\main\java\com\example\myapplication\NativeLibrary.java:27: warning: [unchecked] position(long) in NativeClass overrides <P>position(long) in Pointer
        @Override public NativeClass position(long position) {
                                     ^
  return type requires unchecked conversion from NativeClass to P
  where P is a type-variable:
    P extends Pointer declared in method <P>position(long)
E:\develop\android\sample-projects\gradle-javacpp-android\app\src\main\java\com\example\myapplication\NativeLibrary.java:30: warning: [unchecked] getPointer(long) in NativeClass overrides <P>getPointer(long) in Pointer
        @Override public NativeClass getPointer(long i) {
                                     ^
  return type requires unchecked conversion from NativeClass to P
  where P is a type-variable:
    P extends Pointer declared in method <P>getPointer(long)
2 warnings

> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:compressDebugAssets UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugJavaResource UP-TO-DATE
> Task :app:checkDebugDuplicateClasses UP-TO-DATE
> Task :app:desugarDebugFileDependencies UP-TO-DATE
> Task :app:mergeExtDexDebug UP-TO-DATE
> Task :app:mergeLibDexDebug UP-TO-DATE
> Task :app:dexBuilderDebug
> Task :app:configureCMakeDebug[arm64-v8a]
> Task :app:mergeProjectDexDebug
> Task :app:buildCMakeDebug[arm64-v8a]
> Task :app:configureCMakeDebug[armeabi-v7a]
> Task :app:buildCMakeDebug[armeabi-v7a]
> Task :app:configureCMakeDebug[x86]
> Task :app:buildCMakeDebug[x86]
> Task :app:configureCMakeDebug[x86_64]
> Task :app:buildCMakeDebug[x86_64]
> Task :app:externalNativeBuildDebug
> Task :app:mergeDebugJniLibFolders UP-TO-DATE
> Task :app:mergeDebugNativeLibs UP-TO-DATE
> Task :app:stripDebugDebugSymbols UP-TO-DATE
> Task :app:validateSigningDebug UP-TO-DATE
> Task :app:writeDebugAppMetadata UP-TO-DATE
> Task :app:writeDebugSigningConfigVersions UP-TO-DATE
> Task :app:packageDebug
> Task :app:createDebugApkListingFileRedirect UP-TO-DATE
> Task :app:assembleDebug

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1s
41 actionable tasks: 15 executed, 26 up-to-date

Build Analyzer results available
saudet commented 2 years ago

Please update the task names as per issue #22.

saudet commented 2 years ago

Duplicate of #22