Search code examples
androidaapt

Apk was compiled manually but aapt reported an error


I'm manually compiling an apk. But there is an error in packaging when using aapt.

Create a simple project in Android Studio. Then use aapt to package his resources。 The command is shown below:

aapt package -f -m -J build -S res -M AndroidManifest.xml 
-I /SDK/platforms/android-28/android.jar

The error output is as follows:

error: resource style/Theme.AppCompat.Light.NoActionBar (aka com.jz.myapplication:style/Theme.AppCompat.Light.NoActionBar) not found.
./res/values/styles.xml:6: error: style attribute 'attr/colorPrimary (aka com.jz.myapplication:attr/colorPrimary)' not found.
./res/values/styles.xml:7: error: style attribute 'attr/colorPrimaryDark (aka com.jz.myapplication:attr/colorPrimaryDark)' not found.
./res/values/styles.xml:8: error: style attribute 'attr/colorAccent (aka com.jz.myapplication:attr/colorAccent)' not found.
error: failed linking references.

Solution

  • You are missing resources from the app compat library.

    If you're going to use resources from some libraries, you need to include all of the resources from these libraries and their transitive dependencies using the -S flag. You also need to be mindful of the order of these inputs as they will impact the resource overrides at run-time.

    If you use the Android Gradle Plugin instead all of this will be done automatically for you.