Pass minimum api level to smali library #1313

Merged
merged 1 commit into from Sep 18, 2016

Conversation

Projects
None yet
2 participants
@benjamin-promon
Contributor

benjamin-promon commented Sep 5, 2016

When apktool creates a DexBuilder class, it creates it without specifying a minimum api level. This causes the DexBuilder class to assume api level 20 by default. This is not ideal since in some cases, the concrete minimum api level is required.

One such case is in smali's DexWriter class which implements a workaround for a bug in Dalvik that was fixed in Android 4.2 (https://code.google.com/p/android/issues/detail?id=35304) that causes apps that call the Method.getParameterAnnotations api to crash in some cases (see bug report for more details). The workaround that smali implements is only triggered if the minimum api level is below 17 (Android 4.2). But since apktool effectively sets the minimum api level to 20, this code is never triggered causing apktool to create apk files that crash on devices below Android 4.2.

This change passes the minimum api level to the smali library.

@iBotPeaches

This comment has been minimized.

Show comment
Hide comment
@iBotPeaches

iBotPeaches Sep 6, 2016

Owner

Thanks for the PR. I have a lot of local work in progress for Android Nougat stuff, but the instant I get that settled I'll get this merged.

Thanks again

Owner

iBotPeaches commented Sep 6, 2016

Thanks for the PR. I have a lot of local work in progress for Android Nougat stuff, but the instant I get that settled I'll get this merged.

Thanks again

@iBotPeaches iBotPeaches added the Accepted label Sep 6, 2016

@iBotPeaches

Code looks good, just some minor code style things before I can merge.

@@ -278,6 +279,9 @@ public void build(ExtFile appDir, File outFile)
mAndRes.setVersionInfo(meta.versionInfo);
mAndRes.setSharedLibrary(meta.sharedLibrary);
+ if (meta.sdkInfo != null && meta.sdkInfo.get("minSdkVersion") != null)

This comment has been minimized.

@iBotPeaches

iBotPeaches Sep 14, 2016

Owner

Can you use braces for added logic? I try to stay away from single statement control flow as its just prone to errors.

@iBotPeaches

iBotPeaches Sep 14, 2016

Owner

Can you use braces for added logic? I try to stay away from single statement control flow as its just prone to errors.

}
private void build() throws AndrolibException {
try {
- DexBuilder dexBuilder = DexBuilder.makeDexBuilder();
+ DexBuilder dexBuilder;
+ if (mApiLevel > 0)

This comment has been minimized.

@iBotPeaches

iBotPeaches Sep 14, 2016

Owner

Same as previous comment, use braces here instead of single statements.

@iBotPeaches

iBotPeaches Sep 14, 2016

Owner

Same as previous comment, use braces here instead of single statements.

Pass minimum api level to smali library
When apktool creates a DexBuilder class, it creates it without specifying a minimum api level. This causes the DexBuilder class to assume api level 20 by default. This is not ideal since in some cases, the concrete minimum api level is required.

One such case is in smali's DexWriter class which implements a workaround for a bug in Dalvik that was fixed in Android 4.2 (https://code.google.com/p/android/issues/detail?id=35304) that causes apps that call the Method.getParameterAnnotations api to crash in some cases (see bug report for more details). The workaround that smali implements is only triggered if the minimum api level is below 17 (Android 4.2). But since apktool effectively sets the minimum api level to 20, this code is never triggered causing apktool to create apk files that crash on devices below Android 4.2.

This change passes the minimum api level to the smali library.

@iBotPeaches iBotPeaches self-assigned this Sep 18, 2016

@iBotPeaches iBotPeaches added this to the 2.2.1 - Android Nougat milestone Sep 18, 2016

@iBotPeaches iBotPeaches merged commit db35f54 into iBotPeaches:master Sep 18, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment