Android build .jar from command line fails - android

I would like to generate some .jar for tools to include in an Android project.
So I use command tool "javac" which works great.
But when I try to use Android SDK, it fails:
C:\Dev\Tools.java:123: package android.util does not exist
android.util.Log.d("MYTAG", "hello !");
To compile, I use this command:
"C:\Program Files (x86)\Java\jdk1.6.0_23\bin\javac.exe" -g -d C:\Gen C:\Dev\Tools.java
Any help?

"javac" is the Java compiler, not the tool used to create JAR files, so just compiling a class does not generate a jar file
To be able to compile a class, you must also tell the compiler where it can find the required libraries. This is automatically done for system libraries, but you'll have to pass the path to the Android libraries. This can be done by specifying the folders/jar files using the -classpath parameter on the command line, or by adding it to the respective CLASSPATH environment variable.

Related

How to build Android Archive Library(AAR) with Android Build Tools?

I want to build aar files but I dont have Android Studio as my computer cannot run it.
How to build it from command line using the raw build tools; no gradle included?
The steps to build apk are:
generate R.java file with (aapt).
compile src files including R.java with (javac)
dex classes with (dx)
package, sign, align.
I understand that aar manifest(s) are not compiled to binary format. Thus the first step may not work when creating aar libs.
Please, I am begging, how to, the steps to creating with the build tools.
./gradlew <moduleName>:bundle<build_variant>Aar
//for example
./gradlew app:bundleReleaseAar

How do I add media codecs support to Crosswalk while using the Cordova plug-in?

I'm building a PhoneGap app which needs to play AAC audio. It works well using the native WebView, but I would like to use Crosswalk on a build targeting APIs 16-20 because some CSS features in my app do not work at all on Android 4.x.
When I make a copy of the project to add Crosswalk Lite, I can see that the app works except for the <audio> element pointing to a AAC file. This is because Crosswalk does not ship with proprietary codecs by default.
The linked page says:
To build Crosswalk with these codecs, a developer must run the build
with the “must accept a EULA” switch turned on:
$ xwalk/gyp_xwalk -Dmediacodecs_EULA=1
Then build Crosswalk. The ffmpegsumo.dll or libffmpegsumo.so in
the build output directory will contain the proprietary codecs.
Refer to Crosswalk Build Instruction for more details.
However, I am adding Crosswalk using the suggested plug-in, thus I get pre-built libraries without proprietary codecs:
phonegap plugin add cordova-plugin-crosswalk-webview --variable XWALK_MODE="lite" --save
How can I integrate proprietary codecs in the Cordova Crosswalk plug-in?
I managed to understand the (convoluted) process of building everything. This answer deals with the process of compiling a custom build of the full Crosswalk (not the lite version).
Actually, I decided to finally use the standard build and replace AAC audio with MP3s, but I thought this answer could be useful for future reference.
Environment
I compiled Crosswalk in a Ubuntu 16.04 Docker container to avoid "polluting" my system and to ensure I had the right Linux version. The standard image is pretty barebones so I installed some dependencies. I also set up a shared folder to access the compiled files:
docker run -it -v /home/andrea/shared:/shared ubuntu:16.04 /bin/bash
apt update
apt install -y python git nano lsb-release sudo wget curl software-properties-common
export EDITOR=nano # life it too short to learn vi
Finally, it is necessary to add the multiverse repositories:
apt-add-repository multiverse
Note: this procedure needs a lot of space. Make sure to have at least 25GB of free space before continuing.
Requirements
Install the depot_tools as outlined in the documentation:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:/path/to/depot_tools
Initialize a working directory with:
mkdir crosswalk-checkout
cd crosswalk-checkout
export XWALK_OS_ANDROID=1
gclient config --name src/xwalk https://github.com/crosswalk-project/crosswalk.git
Then edit the config file with nano .gclient and add the following line:
target_os = ['android']
Save the file.
Fetching the source
Attempt a first sync with:
gclient sync
This command will fail but it's OK. The instructions say:
Do not worry if gyp_xwalk fails due to missing dependencies; installing them is covered in a later section, after which you can run gyp_xwalk manually again.
Adjust the install-build-deps.sh file and then run it:
sed -si "s/msttcorefonts/ttf-mscorefonts-installer/g" src/build/install-build-deps.sh
sudo ./src/build/install-build-deps-android.sh
Run gclient sync again and wait until it finishes correctly.
Building
By inspecting the files src/xwalk/build/common.gypi and src/tools/mb/mb_config.pyl, we can see that we need to add ffmpeg_branding="Chrome" in the build arguments.
To prevent an error later on, install the development package related to libnotify:
sudo apt install libnotify-dev
Move to the src directory and open the configuration:
cd src/
gn args out/Default
Ensure the content is as follows:
import("//xwalk/build/android.gni")
target_os = "android"
is_debug = false
ffmpeg_branding = "Chrome"
use_sysroot = false
The parameters use_sysroot = false prevents yet another error. When saving the file, you should see something like this:
Waiting for editor on "/home/utente/crosswalk-checkout/src/out/Default/args.gn"...
Generating files...
Done. Wrote 6060 targets from 1003 files in 2416ms
Issue cd .. and run gclient sync again.
Finally, to build the core library do:
cd src/
ninja -C out/Default xwalk_core_library
This will build the library for ARM, producing an AAR file located at:
src/out/Default/xwalk_core_library.aar
Copy this file in a safe place.
Building for x86
Get back to the args with:
gn args out/Default
Add the following line:
target_cpu = "x86"
Save the file, run gclient sync again and then repeat the ninja command. Make a copy of the new AAR file which now contains the x86 libraries.
Using the AAR files
The standard Cordova Crosswalk plug-in uses a single AAR file with libraries for both platforms. This message by Raphael Kubo da Costa suggests how to produce this single archive:
AAR files are just zip files; given the only difference between the ARM
and x86 AAR files are the different shared libraries, you can use
something like zipmerge or anything that merges zip files (or even
extract everything into some directory and then create one new zip file)
to build one final, multi-architecture AAR archive.
Finally, to use the custom built AAR file in the Cordova plug-in, see How to change the Crosswalk version used by the Cordova Crosswalk Webview plugin.

Android NDK "Error: Could not find class file.." Android Studio & Windows 7

I have a problem with Android NDK to Make the following command ... I have installed NDK and complimented ...
C:\Users\Eduu\AndroidStudioProjects\ndk>javah -jni -classpath C:\Users\Eduu\AppData\Local\Android\sdk\platforms\android-19\android.jar;bin\classes\ -d jni\ com.example.eduu.ndk.MainActivity
Error: Could not find class file for 'com.example.eduu.ndk.MainActivity'.
Link Tutorial: Step 3.3 https://geekytheory.com/hola-mundo-con-android-ndk-parte-4/
Thanks.
The path bin\classes\ is specific for Eclipse project structure. With the default structure of Android Studio project, your command line should look like
C:\Users\Eduu\AndroidStudioProjects\ndk>javah -jni -classpath C:/Users/Eduu/AppData/Local/Android/sdk/platforms/android-19/android.jar;app/build/intermediates/classes/debug -d app/src/main/jni com.example.eduu.ndk.MainActivity
Note that I use forward slash everywhere, to avoid glitches. Also, both paths to jni directory and to the classes directory that I use above, are default paths for Android Studio. These may change per project. You should manually look for the directory where your .cpp files are an where the compiler puts the .class files, whenever you have suspicion that the paths may be different.
Another Simple solution for build class in android studio is
In terminal,
cd app/src/main
then,
javah -d jni -classpath ../../build/intermediates/classes/debug location of class file

Fatal Error: openssl/evp.h No such file or directory

I successfully compiled openssl using android ndk build and .so files are built successfully.
I am trying to 'include' built .so files in an android project.
Getting an error in below line:
#include "openssl/evp.h"
fatal error: openssl/evp.h: No such file or directory
compilation terminated.
make: * [obj/local/armeabi/objs/iedemo/anotherdemo.o] Error 1
However, I am include stdio.h and string.h files.
I am explore /usr/include/openssl directory, I am able find all openssl related .h files here. And, stdio.h and string.h files are present in /usr/include directory.
I have installed libssl-dev package too. Command (sudo apt-get install libssl-dev)
Please help me!!
When encountering this problem on Debian or Ubuntu, it can be solved with the following command:
apt-get install libssl-dev
For people like me, that uses windows OS and they accidently came to this page and the above solutions did not solve their problem, can try the following solution:
I downloaded the OpenSSL executable from the official website, and selected the file with the description that contanins the following line (Recommended for software developers by the creators of OpenSSL).
At the time of writing this solution, the file version is (Win64 OpenSSL v3.0.0), and it can be directly downloaded from the following link.
Here is an Image for more declaration:
After that, I did the following steps:
Install the OpenSSL form the .exe file.
Copy the bin folder directory path (in my case it was C:\Program Files\OpenSSL-Win64\bin) and add it to the system enviroment variables.
Copy the include folder directory path (in my case it was C:\Program Files\OpenSSL-Win64\include) and add it to the system enviroment variables.
Then compile the source code that used the openssl library and header files, they should be compiled with no errors.
Your Android.mk should specify the openssl include directory (not /usr/include/openssl, but the one that goes with the files that you built for Android using NDK. Something similar to
LOCAL_C_INCLUDES += /home/Charan/openssl/include
But you will also need to specify the path for .so files that you have built, and make sure they are correctly deployed with your app. The things can go messy, but luckily there is a working example: openSSL using Android's NDK problems.
I ran into this when building a PHP package using PECL and was able to install the header file as part of openssl-devel
On CentOS/RHEL: yum install openssl-devel
On Ubuntu/Debian: apt-get install openssl-devel

Managing android projects from command line

I am managing and running my android app from command line without using ant, I followed these steps:
generate R.java
compile R.java and all .java files in src to .class files
assembling set of class files into dex file using the command below
dx --dex --verbose --output=./bin/classes.dex ./bin
.class files are in bin directory.
But I'm getting the following errors in these steps:
java.lang.Runtime exception:.\bin file not found
at com.android.dx.cf.direct.ClassPathOpener.process
at com.android.dx.command.dexer.Main.processOne
at com.android.dx.command.dexer.Main.processAllFiles
at com.android.dx.command.dexer.Main..run
at com.android.dx.command.dexer.Main.main
at com.android.dx.command.Main.main
Due to this, I'm unable to create the Classes.dex file.
Can someone suggest a solution for this?
[not using eclipse and ant only through command line]
If you need to "manage your Android projects from command line", when you should use Ant build.
Ant's build.xml is a official standardized way to build Android projects. Ant scripts can do anything you may need to build your project.
If you want most modern build tools for Android, you can look at Gradle for Android projects. Note: today it's still in alpha stage.
Try entering the full path instead of the relative path.
Also you must put the class files inside a directory named exactly like it's package name. for example for com.test.me.MyActivity you must use com/test/me/MyActivity.class
And since we are on the topic, remember that dx can only work with class files created using Java6 (or less) so if you are using java7 to compile your code, add "source 1.6 target 1.6" parameters to your command line.

Categories

Resources