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 with newer Android Gradle plugin version #22

Closed
TimPushkin opened this issue Apr 21, 2022 · 3 comments
Closed

Android example with newer Android Gradle plugin version #22

TimPushkin opened this issue Apr 21, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@TimPushkin
Copy link

I'm not sure if this issue should be put here or in /~https://github.com/bytedeco/sample-projects, sorry if I misplace it.

So, the current example for Android uses com.android.tools.build:gradle:4.1.1 and it builds fine, but when I update the Android plugin to 7.1.3, the project won't build complaining that jniNativeLibrary.cpp and jnijavacpp.cpp cannot be found:

Build command failed.
Error while executing process C:\Users\<my username>\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C <my project path>\gradle-javacpp-android\app\.cxx\Debug\3n4fu1n1\arm64-v8a native-lib}
ninja: Entering directory `<my project path>\gradle-javacpp-android\app\.cxx\Debug\3n4fu1n1\arm64-v8a'
[1/3] Building CXX object CMakeFiles/native-lib.dir/jniNativeLibrary.cpp.o
FAILED: CMakeFiles/native-lib.dir/jniNativeLibrary.cpp.o 
C:\Users\<my username>\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --gcc-toolchain=C:/Users/<my username>/AppData/Local/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/<my username>/AppData/Local/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64/sysroot  -Dnative_lib_EXPORTS  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/native-lib.dir/jniNativeLibrary.cpp.o -MF CMakeFiles\native-lib.dir\jniNativeLibrary.cpp.o.d -o CMakeFiles/native-lib.dir/jniNativeLibrary.cpp.o -c <my project path>/gradle-javacpp-android/app/src/main/cpp/jniNativeLibrary.cpp
clang++: error: no such file or directory: '<my project path>/gradle-javacpp-android/app/src/main/cpp/jniNativeLibrary.cpp'
clang++: error: no input files
[2/3] Building CXX object CMakeFiles/native-lib.dir/jnijavacpp.cpp.o
FAILED: CMakeFiles/native-lib.dir/jnijavacpp.cpp.o 
C:\Users\<my username>\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --gcc-toolchain=C:/Users/<my username>/AppData/Local/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/<my username>/AppData/Local/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64/sysroot  -Dnative_lib_EXPORTS  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/native-lib.dir/jnijavacpp.cpp.o -MF CMakeFiles\native-lib.dir\jnijavacpp.cpp.o.d -o CMakeFiles/native-lib.dir/jnijavacpp.cpp.o -c <my project path>/gradle-javacpp-android/app/src/main/cpp/jnijavacpp.cpp
clang++: error: no such file or directory: '<my project path>/gradle-javacpp-android/app/src/main/cpp/jnijavacpp.cpp'
clang++: error: no input files
ninja: build stopped: subcommand failed.

And indeed jniNativeLibrary.cpp and jnijavacpp.cpp are not built. I figure that probably JavaCpp tasks dependencies need to be changed in app/build.gradle, but I'm struggling to do it on my own. Can you please update the example project?

@saudet
Copy link
Member

saudet commented Apr 21, 2022

Right, that probably needs to be updated. I'm guessing some of the tasks from the plugin for Android have changed, so try to update their names and see if that works.

@saudet saudet added enhancement New feature or request help wanted Extra attention is needed labels Apr 21, 2022
@TimPushkin
Copy link
Author

TimPushkin commented Apr 21, 2022

It seems that the task with name "generateJsonModel$variantName" on which externalNativeBuild<variant name> used to depend no longer exists, but several tasks with names of format "configureCMake$variantName[<ABI name>]" for different ABIs are now among the predecessors of the tasks that build native code with CMake.

So, after I replaced def generateJson = project.tasks.getByName("generateJsonModel$variantName") with

def configureCMake = project.tasks.findAll {
    it.name.startsWith("configureCMake$variantName")
}

and generateJson.dependsOn "javacppBuildCompiler$variantName" with

configureCMake.forEach {
    it.dependsOn "javacppBuildCompiler$variantName"
}

the example builds successfully with com.android.tools.build:gradle:7.1.3.

@saudet
Copy link
Member

saudet commented Nov 3, 2022

I've updated the README.md file as per your findings. Thanks for reporting!

@saudet saudet closed this as completed Nov 3, 2022
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

2 participants