I am trying to create android project with gradle from command line using this command:
android create project \
--target android-23 \
--name HelloWorld \
--path HelloWorld/ \
--activity MainActivity \
--package com.example.helloworld \
--gradle \
--gradle-version 1.3.0
Project structure was successfully generated but when I try to run gradlew assembleDebug I get:
A problem occurred evaluating root project 'HelloWorld'.
> Could not create plugin of type 'AppPlugin'.
I was traversing google for half of day and finally I found that usage of gradle in android create project is (probably) deprecated:
https://code.google.com/p/android/issues/detail?id=160032
Are there any supported methods (that are clean, no hacks) to achieve the goal (in command line)?
As instructed here:
http://eqdn.tech/android-development-on-the-command-line/
You can still use "android create project", but will need to adjust the results manually a little bit afterwards. Essentially changing in gradle/wrapper/gradle-wrapper.properties this:
distributionUrl=http://services.gradle.org/distributions/gradle-1.12-all.zip
To this:
distributionUrl=http://services.gradle.org/distributions/gradle-2.2.1-all.zip
And changing "runProguard false" to "minifyEnabled true" in build.gradle.
Related
I'm trying to build tflite in my android project using cmake. I've managed to work this approach on the linux (debian) version of the same project.When compiling the arm64 version I followed the official docs When I open android studio and press build/run on top right corner, I get this error:
In file included from /home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite/python/interpreter_wrapper/numpy.cc:17:
In file included from /home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite/python/interpreter_wrapper/numpy.h:49:
In file included from /usr/include/python3.9/Python.h:8:
/usr/include/python3.9/pyconfig.h:9:12: fatal error: 'aarch64-linux-gnu/python3.9/pyconfig.h' file not found
When I open the file that throws the error I see the this line indicating that it's searching for it in the system:
#include <aarch64-linux-gnu/python3.9/pyconfig.h>
I ran sudo find / -name "aarch64-linux-gnu" to see whether I have that file or not and indeed I have this file installed:
user#debian:~$ sudo find / -name "aarch64-linux-gnu"
...
/home/user/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/aarch64-linux-gnu/include/c++/8.3.0/aarch64-linux-gnu
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/usr/lib/mesa-diverted/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu
/usr/share/gdb/auto-load/lib/aarch64-linux-gnu
/usr/share/gdb/auto-load/usr/lib/aarch64-linux-gnu
/usr/include/finclude/aarch64-linux-gnu
/usr/include/aarch64-linux-gnu
I located inside /usr/include/aarch64-linux-gnu and indeed saw /python3.9/pyconfig.h.
The way I did everything is this:
sudo git clone https://github.com/tensorflow/tensorflow.git /home/user/Desktop/official_stuff/tensorflow_src
curl -LO https://storage.googleapis.com/mirror.tensorflow.org/developer.arm.com/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz
mkdir -p ${HOME}/toolchains
tar xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C ${HOME}/toolchains
ARMCC_PREFIX=${HOME}/toolchains/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-
ARMCC_FLAGS="-funsafe-math-optimizations"
cmake -DCMAKE_C_COMPILER=${ARMCC_PREFIX}gcc \
-DCMAKE_CXX_COMPILER=${ARMCC_PREFIX}g++ \
-DCMAKE_C_FLAGS="${ARMCC_FLAGS}" \
-DCMAKE_CXX_FLAGS="${ARMCC_FLAGS}" \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
../tensorflow/lite/
And then I needed to ran dpkg --add-architecture arm64, apt-get update, sudo apt install libpython3-dev:arm64
I simply clicked build ran after connecting my android device. It compiled for a while and then throw the error.
Here is the cmake snippet I ran that contains my tflite inclusion:
set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project" )
if(NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"/home/user/Desktop/official_stuff/tensorflow_src" ABSOLUTE)
endif()
add_library(tensorflowlite SHARED IMPORTED)
add_subdirectory(
"/home/user/Desktop/official_stuff/tensorflow_src/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL
)
...
target_link_libraries(
my_proj
tensorflow-lite
)
How can I fix this issue?
Note: I got to this point following a series of questions which all resolved:
An undefined error.
Question regarding android build.
More details about how I built everything can be found here. I'm on debian 11.
I am trying for over one week to compile OpenCV 3.1.0 for Android with NDK r18 on Ubuntu 18.04.
I have used the following command:
cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DANDROID_NDK="/home/qamaruddin/Downloads/android-ndk-r18-linux-x86_64/android-ndk-r18/" \
-DCMAKE_TOOLCHAIN_FILE="/home/qamaruddin/Downloads/android-ndk-r18-linux-x86_64/android-ndk-r18/build/cmake/android.toolchain.cmake" \
-DANDROID_NATIVE_API_LEVEL=19 \
-DANDROID_ABI="armeabi-v7a" \
-DWITH_CUDA=OFF \
-DWITH_MATLAB=OFF \
-DBUILD_ANDROID_EXAMPLES=OFF \
-DBUILD_DOCS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_TESTS=OFF \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DOPENCV_EXTRA_MODULES_PATH="/opt/opencv_contrib/modules/" \
-DCMAKE_INSTALL_PREFIX:PATH="/home/mig-ocv/ocv-android-310/" \
-DEXECUTABLE_OUTPUT_PATH:PATH="/home/mig-ocv/ocv-android-310/" \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH="/home/mig-ocv/ocv-android-310/" \
-DCMAKE_BUILD_TYPE=Release \
/opt/opencv
Follwed by make & make install/strip.
I have tried different versions of OpenCV 3 such as 3.1.0, 3.4.3, and 3.4.0. I have also tried NDKr15c, NDKr17c, and NDKr18c.
I have tried the following variations:
Change NDK version
Change OpenCV 3 version
Install using python script located at opencv/platforms/androind/setup.py
Build using CMAKE
Use Ninja for CMAKE, but this gives the error: "ninja: error: loading 'build/build.global.ninja': No such file or directory"
Install without Ninja with CMAKE
At the moment, using the above-posted command for CMAKE builds successfully, but I can't change the target install dir since it always builds into /usr/local/ and when I inspect the target directory it does not have the familiar OpenCV for Android structure which is:
1- etc
2- java
3- native --> jni --> include
I wonder what is wrong in my process that makes it so difficult to build OpenCV 3 from source for Android with OpenCV Contrib.
Note that $ANDROID_HOME is set to the android SDKs directory on my system and $ANDROID_NDK is also set.
I have seen all duplicate questions on StackOverflow and other forums, but none seems to work in my case.
When I try to build with Ninja with this command:
cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DANDROID_NDK="$HOME/Downloads/android-ndk-r17b/" \
-DCMAKE_TOOLCHAIN_FILE="$HOME/Downloads/android-ndk-r17b/build/cmake/android.toolchain.cmake" \
-DANDROID_NATIVE_API_LEVEL=21 \
-DANDROID_ABI="armeabi-v7a" \
-DWITH_CUDA=OFF \
-DWITH_MATLAB=OFF \
-DBUILD_ANDROID_EXAMPLES=OFF \
-DBUILD_DOCS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_TESTS=OFF \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DOPENCV_EXTRA_MODULES_PATH="$HOME/ocv/opencv_contrib/modules/" \
-DCMAKE_INSTALL_PREFIX:PATH="$HOME/agusta/ocv-android-310/" \
-DEXECUTABLE_OUTPUT_PATH:PATH="$HOME/agusta/ocv-android-310/" \
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH="$HOME/agusta/ocv-android-310/" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_MAKE_PROGRAM=/usr/bin/ninja \
$HOME/ocv/opencv
I get:
CMake Deprecation Warning at CMakeLists.txt:72 (cmake_policy):
The OLD behavior for policy CMP0022 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:77 (cmake_policy):
The OLD behavior for policy CMP0026 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:82 (cmake_policy):
The OLD behavior for policy CMP0042 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
-- Check for working CXX compiler: /home/qamaruddin/Downloads/android-ndk-r17b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
CMake Error: Generator: execution of make failed. Make command was: "/usr/bin/ninja" "cmTC_c4cee/fast"
-- Check for working CXX compiler: /home/qamaruddin/Downloads/android-ndk-r17b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- broken
CMake Error at /usr/local/share/cmake-3.12/Modules/CMakeTestCXXCompiler.cmake:45 (message):
The C++ compiler
"/home/qamaruddin/Downloads/android-ndk-r17b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/qamaruddin/agusta/temp/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/ninja" "cmTC_c4cee/fast"
No such file or directory
Generator: execution of make failed. Make command was: "/usr/bin/ninja" "cmTC_c4cee/fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:93 (project)
-- Configuring incomplete, errors occurred!
See also "/home/qamaruddin/agusta/temp/CMakeFiles/CMakeOutput.log".
See also "/home/qamaruddin/agusta/temp/CMakeFiles/CMakeError.log".
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/clang++
CMAKE_C_COMPILER= /usr/bin/clang
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_ANDROID_EXAMPLES
BUILD_DOCS
BUILD_PERF_TESTS
BUILD_TESTS
EXECUTABLE_OUTPUT_PATH
OPENCV_EXTRA_MODULES_PATH
WITH_CUDA
WITH_MATLAB
-- Build files have been written to: /home/qamaruddin/agusta/temp
I have managed to get it to work, basically, OCV didn't support NDKr18, and I also had to install ninja from source. I have also used python3 instead of python2 to run the opencv/platforms/android/build_sdk.py . One more thing is that I use Eclipse Android ADT which Google has for no reason deprecated ;(, but I find it super fast compared to the heavy Android Studio.
# export ANDROID_ABI=armeabi-v7a
# export ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.8
# export ANDROID_NDK=$HOME/Downloads/android-ndk-r17c-linux-x86_64/android-ndk-r17c/
# export ANDROID_SDK=$HOME/android-sdks/
./../opencv/platforms/android/build_sdk.py --extra_modules_path=/opt/opencv_contrib/modules --config ../opencv/platforms/android/ndk-17.config.py
I have read a helpfull tread however there is some things that are missing. I can create project from command line
android create project --gradle --gradle-version 0.12.2 \
--package com.test.test \
--activity TestActivity \
--target 1 \
--path AutoAndroidApp \
However, this does not create an identical structure as if I would create a project with the android studio. For example from GUI application is put in app folder, also there is build forlder and other differences.
Is there a way to actually reproduce the creation of the project from a command line?
I'm trying to build an apk file from command line. I created a sample project usng the following command:
android create project --target 1 --name MyApp --path ./MyProject --activity MyActivity --package com.example.myapp
Which created the following structure:
/bin
/res
/src
/libs
AndroidManifest.xml
ant.properties
build.xml
local.properties
proguard-project.txt
project.properties
Now when I try to build the project, I get:
$ gradle build
gradle will not execute and completion _gradle exists.
I couldn't find any info on this error, so I ran:
$ _gradle build
_arguments:comparguments:312: can only be called from completion function
user has logged on pts/7 from :0.0.
Any hints on what am I doing wrong? Thanks!
android create project creates project in structure expected by Eclipse, not gradle based (Android Studio) projects.
I was able to build the apk using the following lines:
ant debug
adb install bin/HelloWorld-debug.apk
What I have done is I have taken the class-files from my eclipse project and run them trough an optimizer/obfuscator. So I now have optimized class-files that I want to get in the form of an apk so I can sign and publish it. However, I am lost on how to do this. I guess I cant just copy them into the bin-folder of my eclipse-project, because eclipse would just overwrite them with a new compilation when I try to export a signed apk. So how do I create an apk from these class-files?
you can try to put them in bin/classes and then use "ant" command to build your application
cd /path/to/my/app
ant release
it will ask you every time for your private key to sign the app, it can be configured to auto-sign by editing "build.properties" file:
key.store=release.keystore
key.alias=release
key.store.password=my_key_password
key.alias.password=my_key_password
you can also investigate Android SDK, find the ANT build scripts it actually uses, and insert your custom obfuscator/optimizer call in middle of build process.
Here's an example:
android create project \
--target 1 \
--name MyAndroidApp \
--path ./MyAndroidAppProject \
--activity MyAndroidAppActivity \
--package com.example.myandroid