aapt not working with absolute path - android

I have a kind of strange issue. In my bash script or Makefile, using aapt with absolute path does not work but if I am in the local directory it does.
If I do the following, it does not work:
aapt add $OUT/device.jar $OUT/classes.dex
The command does run and print this output:
'/homes/rsevile/CS307/bin/Device/classes.dex'...
But when trying to load the jar, the class that I am trying to load end up being not found.
The following does work though:
cd $OUT
aapt add device.jar classes.dex
Printing:
'classes.dex'...
This is the whole code being executed in the script (which works):
javac -d $(OUT)/classes -classpath ./layoutlib.jar src/com/device/client/*.java
jar cf $(OUT)/device.jar $(OUT)/classes $(OUT)/layoutlib
dx --dex --no-strict --output=$OUT/classes.dex $OUT/device.jar
cd $OUT
aapt add device.jar classes.dex
cd $ROOT
adb push $OUT/device.jar $ANDROID_OUT_DIR
I am confused why my class ends up being not found when using an absolute path with aapt.
Could anyone please explain to me why it is not working and how I could fix it to use a proper absolute path please?
Thank you.

I realized that aapt actually keeps the absolute path, there is no way around it.
I fixed the problem by reusing jar and using the -C option that lets me specify a directory.

Related

Switch from aapt to aapt2 for native app packaging

We have a great build system, so we're not looking to use gradle. Right now, we use appt to build an APK and it works great and the APK runs well. I see that aapt2 is the future, though, and so we'd like to move to it before we're forced to.
What we currently do:
We have a simple icon in res/mipmap/our_icon.png
We have our ./AndroidManifest.xml file
We have our libMyApp.so stored in apk/lib/armeabi-v7a/libMyApp.so
We build using the following command: aapt package -f -M AndroidManifest.xml -S ./res -I /opt/android-sdk/platforms/android-28/android.jar -F my app-unsigned.apk apk/
We then zipalign and sign using apksigner and the app loads just fine. As you can see, all very simple and gives us just what we need.
I've tried the following with aapt2, but of course it is incorrect:
aapt2 compile ./res/mipmap/our_icon.png -o ./compiled
aapt2 link -v -I /opt/android-sdk/platforms/android-28/android.jar -I compiled/mipmap_our_icon.png.flat --manifest AndroidManifest.xml -o MyApp-unsigned.apk
note: including compiled/minmap_our_icon.png.flat.
error: failed to open APK: Invalid file.
You're trying to provide the resources the way you'd provide an APK (e.g. android.jar):
-I compiled/mipmap_our_icon.png.flat
To pass compiled resources use the -R flag (per each resource or use the wildcard * if you want to pass the whole directory, e.g. compiled/*).
You can find more info on differences between aapt and aapt2 in my old answer here.

dx command error even when path is set

I want to use dx tool. So I use the following command in terminal
dx --dex --output=classes.dex sample.jar
and I got this error
No such file or directory
I know i should set environment variable "path" and add /build-tools/x.y.z/dx to it. But even set the path doesn't resolve the error. I should mention that I can run it from /build-tools/x.y.z/ by running the command
./dx
but i need to access dx from any directory, for my project purpose. I use ubuntu 14.04 64 bit. How can I fix it?

Running apktool in a bash script

I am trying to write a bash script that decompiles several .apk files using apktool. Each apk file is located in a subdirectory of the sample folder.
#!bin/bash
for item in $(ls samples);
do
for apk in $(ls "samples/$item");
do
echo ./apktool/apktool d "./samples/$item$apk"
$(./apktool/apktool d "./samples/$item$apk")
done
done
When I run the script I get the following output:
./apktool/apktool d ./samples/ADRD/53dc.apk*
Input file (./samples/ADRD/53dc.apk*) was not found or was not readable.
The input file error message is the standard for when apktool cannot find a file. However, if I run the following command in the terminal the apktool will work correctly.
./apktool/apktool d ./samples/ADRD/53dc.apk*
I have changed the permissions of all the files located in the samples folder to rw for all users. I also have tried using sudo with the shell script, but this causes the script to hang. However, when I use sudo with the apktool in the command line it also hangs. Therefore, I am not sure if using sudo with apktool is doable.
Any help is appreciated, thanks.
So it looks like this ls gives you an output with an asterisk * appended at the end of the apk filename, because the file is executable.
for apk in $(ls "samples/$item");
This is not the default behaviour of ls, you are getting this probably because you have aliased ls to ls -F or similar. To bypass the alias, rewrite the line this way:
for apk in $(\ls "samples/$item");
Notice the \ I added there.
BTW, is it normal that an apk file is executable? Perhaps you can remove the executable bit:
find samples -name '*.apk' -exec chmod -x {} \;
Also, possibly your script can be replaced with this one liner:
find samples -name '*.apk' -exec ./apktool/apktool d {} \;
Mind you, this is not exactly the same thing, because it may go deeper than two directories. If you need to limit the depth, that's possible too, see man find

Javah class access fail

I wanna use tesseract library with my application so i need to implement ndk.i download it add its path to my bash_profile.
export ANDROID_ADB=/Users/gokhanaliccii/Library/Android/sdk/platform-tools
export ANDROID_NDK=/android_ndk/android-ndk-r10d
export PATH=$PATH:$ANDROID_ADB:$ANDROID_NDK
My problem is appeared when i run -javah command at studio terminal. My command is
javah -d jni -classpath /Users/gokhanaliccii/Library/Android/sdk/platforms/android-19/android.jar:/Users/gokhanaliccii/Documents/gokhan_private/android_ocr/NDK_TEST/app/build/intermediates/classes/debug gokhanaliccii.kou.ndk_test.MainActivity
after i got this error i tried to add support libraries
I tried to solved it but i coulndt find solution i'm really exhausted i hope someone know how to solve it
My project is at /Users/gokhanaliccii/Documents/gokhan_private/android_ocr/NDK_TEST
Dont need cp for javah
Run javac on source that includes file with native headers.
Cd to path that is parent of the root of where the ".class" files are.
On cli or in terminal run the javah ( no cp needed )
If stuvk do the ndk samples and it will make sense . They walk u thru javah sample
After lot of researches and training i solved my problem.
javah -classpath /Users/gokhanaliccii/Library/Android/sdk/platforms/android-19/android.jar:/Users/gokhanaliccii/Library/Android/sdk/extras/android/support/v7/appcompat/libs/android-support-v4.jar:/Users/gokhanaliccii/Library/Android/sdk/extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar:../../build/intermediates/classes/debug -d jni gokhanaliccii.kou.ndk_test.MainActivit
My result command is above.I tried it at android studio,classes files are at build/intermediadtes/classes/debug if you want try it at eclipse it is under bin folder.

How to use Javah in Ubuntu14.04 for HelloNDK?

I am using Ubuntu14.04, Eclipse Luna.
I am referring Hello World Example given link
http://www.ntu.edu.sg/home/ehchua/programming/android/Android_NDK.html
My project name is HelloNDK.
My project path is /home/androiddev/workspace_luna/HelloNDK
In AndroidManifest.xml
I can see package which I use is named as: com.delta.hellondk
Android.jar which automatically added in project which is under Android 5.0.1 & its location shown as
/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar
When I use javah command, I got error.
I use following line in terminal.
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
&
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/JNIActivity.class;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
when I use following command, I got error as follows:
Error: No classes were specified on the command line. Try -help.
bash: /home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar: cannot execute binary file: Exec format error
Now I search lots of keywords in google, stackoverflow regarding how to generate HelloJNI.h automatically.
But i failed.
Please guide me!
I know its repeate question should be get negative vote, should be 'On Hold'. But then also i doesn’t get any clue so i asked without hesitate.

Categories

Resources