Execution failed for task generateJsonModelArmDebug - android

I try to use Android Studio to build native c++ project using cmake 3.14.0 version. Like in documentation: https://developer.android.com/studio/projects/add-native-code#use_a_custom_cmake_version . So I add version "3.14.0" to my build.gradle and add cmake.dir=C\:\\CMakeWin32 to my local.properties about vanilla cmake.
And then:
> Task :UnitTests:generateJsonModelArmDebug
> Task :UnitTests:generateJsonModelArmDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':UnitTests:generateJsonModelArmDebug'.
> Illegal char <:> at index 47: C:/j/client/dava.framework/Programs/UnitTests\C:/r15c/sources/android/cpufeatures/cpu-features.c
If I use default cmake 3.6 in NDK bundle all works. My environment is:
Windows - 10
Android Studio - 3.4.1
gradle - try 4.10.1 and 5.4.1
ndk - try 15c and 19c
In my CMakeLists.txt I add dependency:
add_library( ${PROJECT_NAME} SHARED ${PLATFORM_ADDED_SRC} ${REMAINING_LIST} )
include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()
target_link_libraries( ${PROJECT_NAME} cpufeatures)
I understand from error message full path to C:/r15c/sources/android/cpufeatures/cpu-features.c gradle want's to concatenate with path to current project C:/j/client/dava.framework/Programs/UnitTests. I think problem with gradle and how it use cmake_server to generate json code model. But how to fix it? Thanks in advance.
Update(more info):
If I build like: C:\j\client\dava.framework\Programs\UnitTests\Platforms\Android>gradlew :UnitTests:generateJsonModelArmDebug --info > log.txt 2>&1
in log file copy responce from cmake server and save it in file test.json
open test.json in Firefox and see target libcpufeatures.a in source section has full path to one source file.
sourceDirectory remainse from parent project C:/j/client/dava.framework/Programs/UnitTests
so I think gradle try to combine this two together bug in cmake or in gradle work with json responce from cmake.

Bug was in google gradle plugin so I just upgrade it and it works with new cmake 3.14.
Just update your gradle plugin:
dependencies { classpath 'com.android.tools.build:gradle:3.4.1' }

Related

Bitbucket CI/CD : Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8

I am using Bitbucket CI/CD Pipelines to make a Release build of my Android Application.
Here I am facing an issue while creating Android Release build.
It says
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
And I have tried the same but looks like CI/CD has nothing to do with System and IDE.
Then How should I make gradle work with JAVA 11?
Below is my yml file
image: androidsdk/android-30
pipelines:
default:
- parallel:
- step:
name: Lint
caches:
- gradle
script:
- ./gradlew lint
artifacts:
- app/build/reports/**
- step:
name: Build Release
image: bitbucketpipelines/android-ci-image
caches:
- gradle
script:
- echo $KEYSTORE_FILE_BASE64 | base64 --decode > $KEYSTORE_FILE
- ./gradlew assembleRelease
artifacts:
- app/build/outputs/**
Some of the Answer on here says need to add
image: openjdk:11-jdk
But where should i add that it already have android-30 image to make andorid build

Include headers directories for gradle generation with JNI interaction

I'm trying to get C++ code to work with react-native (see this for the general steps).
I've generated my project with react-native init, generated the JNI bindings by using Djinni. I'm now trying to build the application and test it on my android emulator (cd $PROJECT_ROOT/android && ./gradlew installDebug). It seems like the header files aren't found, their directories aren't included :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:6:10: fatal error: 'cpp_bridge_text.hpp' file not found
#include "cpp_bridge_text.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
I managed to get past this small issue by creating hard links to the headers causing issues. Which leads me to this :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:7:
$PROJECT_ROOT/app/src/main/jni/djinni_support.hpp:20:10: fatal error: 'exception' file not found
#include <exception>
^~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
In this case, it seems like even standard libraries aren't included.
My question is : how do I explicitly specify gradle to add directories to its search/indlude path?
In regular Android projects, it seems that you can edit Android.mk/Application.mk files. There aren't such files in my folders ; I think that gradle actually generates an Android.mk file (in $PROJECT_ROOT/android/app/build/intermediates/ndk/debug/Android.mk), I tried editing it (LOCAL_C_INCLUDES field) to add my directories, but it gets overwritten when I try another build.
Thanks in advance.
You can edit this in $PROJECTROOT/android/app/build.gradle :
android {
defaultConfig {
(...)
ndk {
(...)
cFlags = "-Ipath/to/directory/"
}
}
}
However, you will most likely encounter other issues (I know that for a fact, because I did). I'd recommend you to use the modern and user-friendly CMake integration.
I'm gonna write down the general steps so that I can find it again sometime in the future :
Add your files to the android project (under android studio or another IDE). There should be files in your java/ folder, files in your jni/ folder (JNI bridge files), and files in your cpp/ folder (the native C++).
Add a CMakeLists.txt file to your module (usually named app if you're using react-native).
In this file, respect the following structure :
cmake_minimum_required(VERSION 3.4.1)
add_library( # Name of the library
$(YOUR_LIBRARY_NAME)
# Sets it as a shared library
SHARED
# Relative path to the source file(s)
path/to/your/file.cpp path/to/other/file.cpp )
# Allows you to add folders to the search path : similar to -Ipath/to/your/headerfolder/
include_directories(path/to/your/headerfolder/)
# Allows you to have special compilation flags for the specified library's compilation
target_compile_options( $(YOUR_LIBRARY_NAME)
PRIVATE # You can also use PUBLIC/INTERFACE
-std=gnu++11 ) # Your option ; I needed this in my case
Once it's done, you need to link gradle to your native library :
If you're using android studio, just use the information available in this guide as it's very well explained.
If you aren't, I also advise you to check out this guide, because it's really well explained.
After that, you can either build the project in android studio, or cd $(PROJECTROOT)/android && ./gradlew installDebug. It should work.
Good luck!

how to ndk setting finished with non-zero exit value 2 on android?

I want to build Gstreamer source and it needs NDK.
I am setting SDK Manager -> Android SDK -> SDK Tools -> NDK install
and I set local.properties dk:dir="C\:\\Users\\ddd\\AppData\\Local\\Android\\sdk\\ndk-bundle.
After setting ndk, I try to build it, but execution failed.
Execution failed for task ':app:ndkBuild'. > Process 'command 'C:\Users\ddd\AppData\Local\Android\sdk\ndk-bundle\ndk-build.cmd" finished with non-zero exit value 2 message.
How to set ndk on android?
To find the specific issue, check the Build tab in Android Studio to see which task is failing. For me it was task "cleanNative".
Then run this task manually from Terminal with --debug option.
On Mac or Linux:
./gradlew cleanNative --debug
On Windows:
gradlew cleanNative --debug
From logs, you can then see why it is failing. In my case it was the wrong ABI settings:
10:24:27.140 [QUIET] [system.out] Android NDK: The armeabi ABI is no longer supported. Use armeabi-v7a.
10:24:27.140 [QUIET] [system.out] Android NDK: NDK Application 'local' targets unknown ABI(s): armeabi
10:24:27.140 [ERROR] [system.err] /Users/michal-home/Library/Android/sdk/ndk-bundle/build/core/setup-app.mk:79: *** Android NDK: Aborting . Stop.
10:24:27.140 [QUIET] [system.out] Android NDK: Please fix the APP_ABI definition in /path-to-app/app/src/main/jni/Application.mk
What I infer from above is that you have already installed NDK, make sure you also install CMake and LLDB. (Restart Android Studio after install)
If the problem persists even after that, try deleting the "obj" folder within your ndk library (located at "yourLibary/main/src/obj") and rebuild.
This solved the problem for me.
You need to make sure the NDK is set properly - go to File->Project Structure->SDK Location and make sure the NDK location is properly set. If it is, perhaps the compilation fails due to some problem with the code, and we will need some more info in order to help you.
In my case and project, it was helpful to use privious ndk version(Revision 17c). So I just have put it in 'C:\Users\UserName\AppData\Local\Android\sdk\ndk-bundle'
Another helpful issue is to put your *.so files within jniLibs folder:
How to include *.so library in Android Studio?
Check your android project path.
I had a similar problem with empty spaces at my folder name. Avoid things like that or ndk can't do the job
.\Users\User1\Desktop\androidprojects\my project\androidproject1
Instead that use
.\Users\User1\Desktop\androidprojects\myproject\androidproject1

tensorflow build fails with “BUILD file not found on package”

I trying build tensorflow_demo for android with Bazel, but I get this error:
ERROR: no such package 'tensorflow/tensorflow/examples/android': BUILD file not found on package path.
I have build file in directory (MacOS):
/Users/pavelgosteev/tensorflow/tensorflow/examples/android
build command:
(tensorflow) MBP-Pavel:tensorflow pavelgosteev$ bazel build //tensorflow/tensorflow/examples/android:tensorflow_demo
What's wrong? Why can't Bazel see build file?
I think you need one fewer "tensorflow" in the build target name. Try:
bazel build //tensorflow/examples/android:tensorflow_demo
Further instructions can be found in the Tensorflow Android tutorial.

Build Android project on command line on OSX: Task 'assembleDebug' not found in root project

I'm trying to build Android projects on the OSX (Mavericks 10.9.5) command line using this how-to: http://developer.android.com/tools/building/building-cmdline.html.
This How-To explains the use of assembleDebug/assembleRelease to build an Android project.
Unfortunately gradle doesn't create the assembleDebug or assembleRelease targets.
Executing ./gradlew assembleDebug returns this:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'assembleDebug' not found in root project 'test'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.826 secs
Steps:
android create project
The test project has been created with android create project --path . --name "DummyAPK" --target android-21 --package com.dummyapk.dummyapk --activity DummyActivity
which returned
Created directory /Users/user/Documents/test/src/com/dummyapk/dummyapk
Added file ./src/com/dummyapk/dummyapk/DummyActivity.java
Created directory /Users/user/Documents/test/res
Created directory /Users/user/Documents/test/bin
Created directory /Users/user/Documents/test/libs
Created directory /Users/user/Documents/test/res/values
Added file ./res/values/strings.xml
Created directory /Users/user/Documents/test/res/layout
Added file ./res/layout/main.xml
Created directory /Users/user/Documents/test/res/drawable-xhdpi
Created directory /Users/user/Documents/test/res/drawable-hdpi
Created directory /Users/user/Documents/test/res/drawable-mdpi
Created directory /Users/user/Documents/test/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt
gradle init
After that I executed gradle init, which returned
:wrapper
:init
BUILD SUCCESSFUL
gradlew tasks
Querying the available tasks with gradlew tasks returns (isn't there missing something?)
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'test'. [incubating]
dependencies - Displays all dependencies declared in root project 'test'.
dependencyInsight - Displays the insight into a specific dependency in root project 'test'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'test'.
properties - Displays the properties of root project 'test'.
tasks - Displays the tasks runnable from root project 'test'.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.474 secs
My Java version is
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
..and Gradle version (installed via brew) is
------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_60 (Oracle Corporation 24.60-b09)
OS: Mac OS X 10.9.5 x86_64
What am I missing to be able to build an Android project on the command line?
android create project does not create a gradle friendly structure. It creates an ant friendly structure. You have two options depending on your intentions.
use ant to build your project ( not currently supported by Android team )
use Android Studio to generate a gradle friendly project structure.
num 2 is the recommended approach by the Android team. It's as simple as dl'ing Android Studio and creating a new project. From there you should be able to create a new project that can be built with ./gradlew build
try This:
./android create project -p AppPAKTGV -a Main -k com.example.apppaktgv -t android-23 -g -v 0.11.+
it's works but when i try target 24 or 25 not work i don't now
Try to do this and note
a) you need to type tools/android under Step 3 (like step 2: Execute)
-- but as said the ant structure is not helpful
-- not sure I can go from there
b) I follow the advice and also ensure get the platform-tools
-- I can build
-- I can get that .apk
-- I can adb install (I rename any existing .apk)
Seems working!

Categories

Resources