Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

bash - How to compile an Android app with aapt2 without using any build tools?

I'm trying to compile an Android application I just created in Kotlin on Android Studio, without using Gradle or any other build tools. My intention is to speed up compiling applications without having to use Android Studio or install build tools like Gradle, ant or buck. I'm running into an issue linking files with aapt2.

I'm compiling all files in res folder into a zip file with aapt2. But when I try to link them aapt2 spits out errors. The errors seem to be due to missing app compat libraries,and my questions is how to successfully link all these and kotlin files to create a deployable apk file.

The following compiles all files in res folder and creates resources.zip file.

$AAPT compile --dir $APP_DIR/src/main/res -o $APP_DIR/build/intermediate/resources.zip    

This however fails.

$AAPT link -o $APP_DIR/build/intermediate/ -I $PLATFORM $APP_DIR/build/intermediate/resources.zip --manifest $APP_DIR/src/main/AndroidManifest.xml

with following errors

error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.example.myapplication:style/Theme.AppCompat.Light.DarkActionBar) not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:6: error: style attribute 'attr/colorPrimary (aka com.example.myapplication:attr/colorPrimary)' not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:7: error: style attribute 'attr/colorPrimaryDark (aka com.example.myapplication:attr/colorPrimaryDark)' not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:8: error: style attribute 'attr/colorAccent (aka com.example.myapplication:attr/colorAccent)' not found.
error: resource style/ThemeOverlay.AppCompat.Dark.ActionBar (aka com.example.myapplication:style/ThemeOverlay.AppCompat.Dark.ActionBar) not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:11: error: style attribute 'attr/windowActionBar (aka com.example.myapplication:attr/windowActionBar)' not found.
./projects/MyApplication/app/src/main/res/values/styles.xml:12: 
error: style attribute 'attr/windowNoTitle (aka com.example.myapplication:attr/windowNoTitle)' not found.
error: resource style/ThemeOverlay.AppCompat.Light (aka com.example.myapplication:style/ThemeOverlay.AppCompat.Light) not found.

error: failed linking references.

This appears to be due to missing app compat libraries.I've tried manually downloading appcompat-v7-27.1.1.aar file and linking it but this to fails.

If anyone has come across a solution to this please enlighten me. Thanks.

I want to replicate what's available here with aapt2 https://github.com/authmane512/android-project-template/blob/master/build.sh

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Actually it is very difficult and messy to use extra support libraries, You are getting those errors, because you are using support library's theme which is not a part of android.jar, Instead you can use android.jar's default theme. Just put

public  class MainActivity extends Activity {...}

in place of

public  class MainActivity extends AppCompatActivity {...}

and change your manifest's App theme pointing to 'styes.xml', So basically you have to change the styles XML file to this one

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

Also you should use below code in 'Manifest.xml' file to point the Theme of your project or Activity in Styles XML file under values

android:theme="@style/AppTheme"

this reference article is very helpful for what exactly you are trying to dohttps://geosoft.no/development/android.html, Also sign your APK in order to run your app on device, otherwise it can show error while installing. Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...