简体   繁体   English

如何在不使用任何构建工具的情况下使用 aapt2 编译 Android 应用程序?

[英]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.我正在尝试编译我刚刚在 Android Studio 上的 Kotlin 中创建的 Android 应用程序,而不使用 Gradle 或任何其他构建工具。 My intention is to speed up compiling applications without having to use Android Studio or install build tools like Gradle, ant or buck.我的目的是加快编译应用程序的速度,而无需使用 Android Studio 或安装 Gradle、ant 或 buck 等构建工具。 I'm running into an issue linking files with aapt2.我遇到了将文件与 aapt2 链接的问题。

I'm compiling all files in res folder into a zip file with aapt2.我正在使用 aapt2 将 res 文件夹中的所有文件编译成一个 zip 文件。 But when I try to link them aapt2 spits out errors.但是当我尝试链接它们时,aapt2 会抛出错误。 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.错误似乎是由于缺少应用程序兼容库,我的问题是如何成功链接所有这些和 kotlin 文件以创建可部署的 apk 文件。

The following compiles all files in res folder and creates resources.zip file.下面编译 res 文件夹中的所有文件并创建 resources.zip 文件。

$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.这似乎是由于缺少应用程序兼容库。我尝试手动下载 appcompat-v7-27.1.1.aar 文件并链接它,但这失败了。

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我想用 aapt2 https://github.com/authmane512/android-project-template/blob/master/build.sh复制这里可用的内容

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.实际上,使用额外的支持库非常困难和混乱,您会收到这些错误,因为您使用的支持库的主题不是 android.jar 的一部分,您可以使用 android.jar 的默认主题。 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并将您的清单的 App 主题更改为指向“styes.xml”,因此基本上您必须将样式 XML 文件更改为此一个

<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此外,您应该在“Manifest.xml”文件中使用以下代码将项目的主题或样式 XML 文件中的活动指向值下

android:theme="@style/AppTheme"

this reference article is very helpful for what exactly you are trying to do https://geosoft.no/development/android.html , Also sign your APK in order to run your app on device, otherwise it can show error while installing.这篇参考文章对您尝试执行的操作非常有帮助https://geosoft.no/development/android.html ,同时签署您的 APK 以便在设备上运行您的应用程序,否则安装时可能会显示错误。 Thanks.谢谢。

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.使用aapt/appt2编译java应用程序参考以下链接,以便您自己编译kotlin。

https://github.com/HemanthJabalpuri/AndroidExplorer https://github.com/HemanthJabalpuri/AndroidExplorer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到com.android.tools.build:aapt2 AndroidStudio - Could not find com.android.tools.build:aapt2 AndroidStudio 找不到 com.android.tools.build:aapt2:3.2.0 - Could not find com.android.tools.build:aapt2:3.2.0 如何解决呢? -“&#39;C:\\ Users \\ dmgop \\ AppData \\ Local \\ Android \\ Sdk \\ build-tools \\ 27.0.3 \\ aapt2.exe上缺少aapt2” - How to solve this? - “aapt2 is missing on 'C:\Users\dmgop\AppData\Local\Android\Sdk\build-tools\27.0.3\aapt2.exe' ” AAPT2编译时错误Android Studio - AAPT2 Compile time error Android Studio Android Studio 3.2 - 找不到com.android.tools.build:aapt2:3.2.0-4818971 - Android Studio 3.2 - Could not find com.android.tools.build:aapt2:3.2.0-4818971 Android Studio找不到com.android.tools.build:aapt2:3.2.0-4818971 - Android studio Could not find com.android.tools.build:aapt2:3.2.0-4818971 Android-找不到com.android.tools.build:aapt2:3.2.1-4818971。 在以下位置搜索: - Android - Could not find com.android.tools.build:aapt2:3.2.1-4818971. Searched in the following locations: Jenkins构建Android的Aapt2问题 - Aapt2 issue with jenkins build Android 找不到 com.android.tools.build:aapt2:3.2.0-4818971 - Could not find com.android.tools.build:aapt2:3.2.0-4818971 找不到 aapt2-4.0.0-6051327-linux.jar (com.android.tools.build:aapt2:4.0.0-6051327) - Could not find aapt2-4.0.0-6051327-linux.jar (com.android.tools.build:aapt2:4.0.0-6051327)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM