Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying android.jar Files on Device (building the aapt, ecj, dx and apksigner packages) #3

Closed
SDRausty opened this issue Oct 25, 2019 · 14 comments
Assignees

Comments

@SDRausty
Copy link
Contributor

Modifying android.jar might better than adding libraries. Hence this issue is devoted to rewriting the android.jar file.

@SDRausty SDRausty added the enhancement New feature or request label Oct 25, 2019
@SDRausty SDRausty pinned this issue Oct 25, 2019
@SDRausty SDRausty self-assigned this Oct 25, 2019
@HemanthJabalpuri
Copy link

@SDRausty
android.jar is available at runtime in android os.

So modifications to it may lead problems.
Also it needs root and different versions of android uses different updated android.jar.

So it is not a good idea to modify it.

@SDRausty
Copy link
Contributor Author

@HemanthJabalpuri do you know the steps to compile and decompile android.jar?

Also it needs root

[09:15~]$ find $PREFIX/ -name android.jar -exec ls -og {} \;
-rw------- 1 3881775 Jul 22 14:39 /data/data/com.termux/files/usr/share/java/android.jar
-rw------- 1 3340986 Jun 19 14:14 /data/data/com.termux/files/usr/share/aapt/android.jar

Why do you state that root is needed?

@SDRausty
Copy link
Contributor Author

@HemanthJabalpuri
Copy link

@SDRausty
Sorry for late reply.

android.jar = /system/framework/framework.[apk & jar] + others too.

We are not compiling android.jar, i.e., we are only including it as classpath assuming that the target device have that in its bootclasspath.
All android devices bootclasspath has framework.jar for executing apps.

So if we want to modify android.jar, we also need to modify framework.jar in device too.

So modifying /system partition needs root.

Also https://github.com/BuildAPKs/buildAPKs.samples app compiled fine without Linux Distribution.

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 1, 2019

including it as classpath

Unifying native artifacts should be a simple solution. File bootclasspath.sh is created to ease inegrating of native libraries that are present on device.

Reference from #2 (comment)

assuming that the target device

MSDKVERSIO="$(getprop ro.build.version.min_supported_target_sdk)" || printf "%s" "signal ro.build.version.min_supported_target_sdk ${0##*/} generated"
 
MSDKVERSION="${MSDKVERSIO:-14}"

TSDKVERSIO="$(getprop ro.build.version.sdk)" || printf "%s" "signal ro.build.version.sdk ${0##*/} generated"

TSDKVERSION="${TSDKVERSIO:-23}"

sed -i "s/minSdkVersion\=\"[0-9]\"/minSdkVersion\=\"$MSDKVERSION\"/g" AndroidManifest.xml 

sed -i "s/minSdkVersion\=\"[0-9][0-9]\"/minSdkVersion\=\"$MSDKVERSION\"/g" AndroidManifest.xml 

sed -i "s/targetSdkVersion\=\"[0-9]\"/targetSdkVersion\=\"$TSDKVERSION\"/g" AndroidManifest.xml 

sed -i "s/targetSdkVersion\=\"[0-9][0-9]\"/targetSdkVersion\=\"$TSDKVERSION\"/g" AndroidManifest.xml

Reference from build.one.bash#L123&#L130

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 1, 2019

Also https://github.com/BuildAPKs/buildAPKs.samples app compiled fine without Linux Distribution.

@HemanthJabalpuri the reason this was requested:

test https://github.com/BuildAPKs/buildAPKs.samples on device with https://github.com/sp4rkie/debian-on-termux please?

Are the errors important? Oh yes, much so.

The BuildAPKs modules/repositories and forks are selected because they compile on device in Termux. Can they compile in a PRoot environment as well as in Termux?

compiled fine without Linux Distribution.

Studying the errors in debian proot has shed a little more light on this subject. I would like to hear your opinion about the errors encountered.

BuildAPKs was recently modified to run after one tap inside a debian proot environment. The script sets up fine, and runs as it should except for the fact that compiling even a single APK is impossible in debian on device. I would like to 👂 hear your opinion about the errors BuildAPKs shows in debian proot on device...

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 1, 2019

@HemanthJabalpuri you mentioned:

All android devices bootclasspath has framework.jar for executing apps.

$ grep -r colorPrimary /system/framework/
Binary file /system/framework/framework-res.apk matches

Referencing Parsing Project Configuration Files #1 issuecomment-534638948:

number of errors / type of error
4813 error: Error: No resource found that matches the given name: attr 'colorPrimary'.

It appears that you are absolutely correct:

$ mkdir tmp
$ cd tmp
$ unzip  -q /system/framework/framework-res.apk
$ grep -r colorPrimary .                                
Binary file ./resources.arsc matches
$ dpkg -S aapt 
.
aapt: /data/data/com.termux/files/usr/share/aapt/android.jar                                                    
.
$ cp /data/data/com.termux/files/usr/share/aapt/android.jar .
$ cp /system/framework/framework-res.apk /data/data/com.termux/files/usr/share/aapt/android.jar

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 1, 2019

Results:

$ grep colorPrimaryDark android.jar 
$ grep colorPrimaryDark /data/data/com.termux/files/usr/share/aapt/android.jar
colorPrimaryDark
$ ~/buildAPKs/build.github.bash google
.
.
.
Running: grep -iC 4 ERROR /data/data/com.termux/files/home/buildAPKs/var/log/stnderr.git.orgs.google.log | tail
res/menu/menu_main.xml:4: error: No resource identifier found for attribute 'orderInCategory' in package 'android'
res/values/styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
res/values/styles.xml:8: error: Error: No resource found that matches the given name: attr 'colorAccent'.                                                       
res/values/styles.xml:6: error: Error: No resource found that matches the given name: attr 'colorPrimary'.                                                                                                                                      
res/values/styles.xml:7: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.

Any ideas why aapt doesn't add colorPrimaryDark to the build even though colorPrimaryDark is in android.jar?

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 6, 2019

aapt doesn't add colorPrimaryDark to the build even though colorPrimaryDark is in android.jar

This commit e705a9a resolves aapt doesn't add colorPrimaryDark.

@HemanthJabalpuri
Copy link

@SDRausty
Since according to your output of grep, you can simply add framework-res.apk to aapt with -I flag of aapt.

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 7, 2019

@HemanthJabalpuri thank you for sharing;
This 29f76de commit adds

framework-res.apk to aapt with -I flag

The verbose output states Including resources from package: /system/framework/framework-res.apk.

However Error: No resource found that matches the given name: attr 'colorPrimaryDark' and similar still persist after further testing.

$ grep -r colorPrimaryDark /system 2>/dev/null | wc -l
76
$ grep colorPrimaryDark /system/framework/framework-res.apk 2>/dev/null | wc -l 
1

@SDRausty
Copy link
Contributor Author

SDRausty commented Dec 8, 2019

add framework-res.apk to aapt with -I flag of aapt

Commit 2fec19a adds support for including many artifacts with the -I flag to aapt. The result still appears to be unchanged and the error continues.

@SDRausty SDRausty changed the title Modifying android.jar Modifying android.jar Files on Device (building the aapt, ecj, dx and apksigner packages) Dec 19, 2019
@github-actions
Copy link

Stale issue message

@github-actions github-actions bot closed this as completed Mar 7, 2020
@SDRausty SDRausty unpinned this issue Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants