2

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

  • I doubt, this would "speed up compiling applications". Gradle does a good job avoiding unnecessary compilations. In which part do you think you could do it faster? – Henry Jan 20 '19 at 08:15
  • Speeding up part is questionable I agree. I just wanted to see if I could do it without using Gradle for a project I'm working on. My plan is to pre-download dependencies gradle pulls in, into a folder and add them during aapt2 linking stage to create an intermediate apk file which I can then merge with kotlin binary files. – Ruchira Bandara Jan 20 '19 at 08:22

2 Answers2

0

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.

0

Use the below link for reference of using aapt/appt2 for compiling java app, so that you can make one for compiling kotlin on your own.

https://github.com/HemanthJabalpuri/AndroidExplorer

HemanthJabalpuri
  • 344
  • 4
  • 11