Apktool: Kotlin Sample App - Build not working

Information

  1. Apktool Version (apktool -version) - 2.2.3-dirty & 2.2.2
  2. Operating System (Mac, Linux, Windows) - Windows
  3. APK From? (Playstore, ROM, Other) - Kotlin Sample App. (https://github.com/JetBrains/kotlin-examples/tree/master/gradle/android-mixed-java-kotlin-project)

Stacktrace/Logcat

I: Using Apktool 2.2.3-dirty
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
W: A/        (15044): First type is not attr!
W:
W: This application has requested the Runtime to terminate it in an unusual way.
W: Please contact the application's support team for more information.
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 3): [C:\Users\USER\AppData\Local\Temp\brut_util_Jar_4058827053303104259.tmp, p, --forced-package-id, 127, --min-sdk-version, 14, --target-sdk-version, 23, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, C:\Users\USER\AppData\Local\Temp\APKTOOL142551802667663674.tmp, -0, arsc, -0, arsc, -I, C:\Users\USER\AppData\Local\apktool\framework\1.apk, -S, C:\Users\USER\Test\app-debugkotlin\res, -M, C:\Users\USER\Test\app-debugkotlin\AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:493)
        at brut.androlib.Androlib.buildResources(Androlib.java:427)
        at brut.androlib.Androlib.build(Androlib.java:326)
        at brut.androlib.Androlib.build(Androlib.java:264)
        at brut.apktool.Main.cmdBuild(Main.java:231)
        at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 3): [C:\Users\USER\AppData\Local\Temp\brut_util_Jar_4058827053303104259.tmp, p, --forced-package-id, 127, --min-sdk-version, 14, --target-sdk-version, 23, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, C:\Users\USER\AppData\Local\Temp\APKTOOL142551802667663674.tmp, -0, arsc, -0, arsc, -I, C:\Users\USER\AppData\Local\apktool\framework\1.apk, -S, C:\Users\USER\Test\app-debugkotlin\res, -M, C:\Users\USER\Test\app-debugkotlin\AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:441)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:479)
        ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 3): [C:\Users\USER\AppData\Local\Temp\brut_util_Jar_4058827053303104259.tmp, p, --forced-package-id, 127, --min-sdk-version, 14, --target-sdk-version, 23, --version-code, 1, --version-name, 1.0, --no-version-vectors, -F, C:\Users\USER\AppData\Local\Temp\APKTOOL142551802667663674.tmp, -0, arsc, -0, arsc, -I, C:\Users\USER\AppData\Local\apktool\framework\1.apk, -S, C:\Users\USER\Test\app-debugkotlin\res, -M, C:\Users\USER\Test\app-debugkotlin\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:95)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:435)
        ... 6 more

Steps to Reproduce

  1. Make a decode of the apk
  2. Try to build the folder again

APK

app-debugkotlin.zip

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 31 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Ugh. I figured it out. Lots of work ahead of me. It appears since a related bug to this was Magisk, I took a look at their GitHub.

https://github.com/topjohnwu/MagiskManager/blob/master/gradle.properties#L25

They use aapt2, which we use aapt1 in apktool. It seems applications built in aapt2 cannot be rebuilt in aapt1 - https://developer.android.com/studio/preview/features/new-android-plugin.html

Options

  1. Hack around these checks in aapt1 and hope it works.
  2. Port apktool to aapt2.

I honestly have no idea at this point. I could intentionally detect anim as the first type and record it as typeId + 1, which then would allow the next type (hopefully attr to be recorded as the first but that would introduce some real problems I foresee.

I’ve reported a bug in AOSP in hopes to get one of the devs more familiar with the aapt engine to put a comment on it - https://issuetracker.google.com/issues/63139950, in the past Adam has helped as he appeared to be the lead on aapt2. We will hold for now and await a response.

  1. kotlin folder at root should not be treated as unknown. It seems to contain annotations and more. Should be handled with copy like lib folder.

  2. public.xml generation is creating a malformed file, thus that error.

Confirmed.

Yep! It was… sorry!

"

Start building New.apk…

I: Using Apktool 2.2.4 W: Could not find sources I: Building resources… W: warning: string ‘numeric_date_template’ has no default translation. W: warning: string ‘switch_locale_button_text’ has no default translation. W: warning: string ‘switch_locale_confirm_msg’ has no default translation. W: Warning: AndroidManifest.xml already defines versionCode (in http://schemas.a ndroid.com/apk/res/android); using existing value in manifest. W: Warning: AndroidManifest.xml already defines versionName (in http://schemas.a ndroid.com/apk/res/android); using existing value in manifest. W: Warning: AndroidManifest.xml already defines minSdkVersion (in http://schemas .android.com/apk/res/android); using existing value in manifest. W: Warning: AndroidManifest.xml already defines targetSdkVersion (in http://sche mas.android.com/apk/res/android); using existing value in manifest. I: Copy original files… I: Copy AndroidManifest.xml… I: Copy META-INF… I: Building apk file… I: Copying unknown files/dir… Prima qualquer tecla para continuar . . .

"

@forkoz We do not have any nightly support. Since this bug is a bit major, I’ve attached a SNAPSHOT release

–removed–

With #1528, I’m closing this as everything should be resolved after some July 4th tests. If another issue crops up related to this, lets open a new report to organize this more. The commits related to this bug fixed

  1. New resources in Dev Preview 2 (O)
  2. Kotlin decoding (without treating it as unknown)
  3. Removing the restrictions on attr type being first in resource table (aapt2)
  4. Adding the $ as an allowed character for resource names.

new_res

Appears that is a new resource added in O Dev Preview. Apktool only has Dev Preview 1. I will update it to Dev Preview 2 shortly.