Compile android project to apk without eclipse - android

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

Related

How to change Install Dir when Building OpenCV 3.1.0 on Ubuntu 18.04 for Android NDK18rc and ARMEABI-7?

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

create android project with gradle from command line deprecated?

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.

Android studio: start project from command line

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?

Building OpenSSL for Android (ARMv7) on Win32

How can I build OpenSSL for Android ARM v7 (using Android NDK) on Win32?
Until the OpenSSL's wiki and setenv-android.sh are updated accordingly, I'll publish the recipe here. The required fixes to the process are:
Update setenv-android.sh to support Windows.
Update PATH to use Android NDK's (mingw) GNU make (rather than Cygwin's).
Invoke make with a Windows-style path to Cygwin's perl.
This recipe will be a strange hybrid of Cygwin and mingw (since Android NDK gcc toolchains for win32 are mingw). I'm assuming a Windows x86_64 build of the Android NDK unpacked into c:\android-ndk-r9d, and that you wish to use a gcc 4.8 toolchain.
Install Android NDK (duh!).
Install Cygwin -- make sure to include perl
Start Cygwin shell as an administrator to make sure native symlinks will work.
Within the console, run the following script to set the variables:
export \
CYGWIN=winsymlinks:native \
ANDROID_API=android-14 \
ANDROID_DEV=c:/android-ndk-r9d/platforms/android-14/arch-arm/usr \
PATH=/cygdrive/c/android-ndk-r9d/prebuilt/windows-x86_64/bin:/cygdrive/c/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin:$PATH \
MACHINE=armv7 \
SYSTEM=android \
ARCH=arm \
CROSS_COMPILE=arm-linux-androideabi-
Now, unpack openssl:
tar xzfv openssl-1.0.1i.tar.gz (or whatever your tarball is)
cd openssl-1.0.1i (or whatever your version is)
Make sure you have actual native Win32 (!) symlinks in include/openssl:
cmd /c "dir include\openssl"
You should see something like:
13-Aug-14 05:59 PM <SYMLINK> aes.h [..\..\crypto\aes\aes.h]
13-Aug-14 05:59 PM <SYMLINK> asn1.h [..\..\crypto\asn1\asn1.h]
(etc.)
Now it's time to configure:
./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/foo/bar
Ignore the failure to build (due to failure to find perl). We'll rectify this right away. Do this:
make PERL=$(cygpath -w $(which perl))
Now wait for a few minutes until it builds, and presto, you have your libcrypto.so etc.
Just a couple of comments on my experience with this:
Executing this statement:
PERL=$(cygpath -w $(which perl))
in the cygwin shell allows the shell to interpret the backslashes as escape characters and the build process chokes. To solve this I did the following:
$ echo $(cygpath -w $(which perl))
which produced the windows formatted path to the perl executable:
C:\cygwin64\bin\perl
Then I added this line to the export shown above:
PERL=c:/cygwin64/bin/perl \
There are other ways of doing this, but it worked and headed off the problem with the ./config statement documented above (not finding perl).
Second issue was the -no- statements. After running the configure, the script reports that you'll have to run make depend. I wanted to exclude MD5 (i.e. -no-md5) and when I did the make depend, it errored out with a report that MD5 was disabled. Uhhh, yes, that was kind of the idea, but I just won't use MD5 hashes. I did use the -no-ssl2 and didn't get any complaints after the make depend.
Third issue and this is a mystery. The build broke on compiling crypto because it could not find a symbol that is supposed to be defined in /crypto/objects/obj_xref.h. When I looked at the file, it was empty. Something in the perl script I suppose, but no time to debug right now, since I'm at proof of concept phase. I placed a copy from a patch that I picked up at https://github.com/devpack/openssl-android
After that, my build ran to completion. I've done no testing with this and it is not a trustworthy solution, but it did compile and produce the static libraries that I need for proof of concept for my client.
Just as an update, my shared library built with these libraries loaded fine on my target.

Dynamically linking to a shared Java Library in Android

I'm trying to separate a Java Library, that is used by multiple Android "services", into a dynamic or shared library that can be loaded by those independent services without having the library included into the APK of each service.
I know there are different ways of doing this like creating an Android Service or using DexLoader and Reflection but I'm trying to avoid changing the source of the library. Instead I'm trying to build it and install it on my device (essentially extending the provided android API).
The following is a very similar question which is still unanswered:
Create Android apps in Eclipse sharing common library
I know this is something Google doesn't want to disclose so finding information online is extremely difficult.
So far I've tried placing a simple "Hello World" program under the frameworks dir and build it which successfully created a jar for my program. Then I added my package in product/core.mk and in addition added my package definition under api/10.xml after which I ran "make sdk" which resulted in the following error message:
******************************
You have tried to change the API from what has been previously released in
an SDK. Please fix the errors listed above.
******************************
make: *** [out/target/common/obj/PACKAGING/checkapi-last-timestamp] Error 38
As a workaround I added my package into "public_api.xml" file, inside the out directory, which is somehow dynamically created during the build process. With this workaround the SDK is built with no errors (although if I do clean again I'll have to modify the public_api.xml again because it will be removed due to clean). However, when I try to import and use my package anywhere it still says that my package "does not exist"
Any help will be greatly appreciated! Thank you!
Finally figured it out. The solution turns out to be very simple!
Place your library in the frameworks/base folder and make sure all your source code is inside under java directory like so:
../frameworks/base/HelloWorld/java/<source files and folders>
Edit core.mk file located under build/target/product/ to include your package in the list. This will add HelloWorld library to the framework:
PRODUCT_PACKAGES := \
bouncycastle \
:
:
DefaultContainerService \
Bugreport \
HelloWorld
Edit pathmap.mk file located under build/core/ to include your directory in the list. This will add HelloWorld library to the android.jar
FRAMEWORKS_BASE_SUBDIRS := \
$(addsuffix /java, \
core \
graphics \
location \
media \
opengl \
sax \
telephony \
wifi \
vpn \
keystore \
voip \
HelloWorld \
)
Done. rebuild android and it should not complain and add your library to framework.jar!
I hope this helps.

Categories

Resources