Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不使用任何构建工具的情况下使用aapt2编译Android应用程序?_Android_Bash_Aapt2 - Fatal编程技术网

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

如何在不使用任何构建工具的情况下使用aapt2编译Android应用程序?,android,bash,aapt2,Android,Bash,Aapt2,我正在尝试编译一个我刚刚在Android Studio上的Kotlin中创建的Android应用程序,而不使用Gradle或任何其他构建工具。我的目的是加快编译应用程序的速度,而不必使用Android Studio或安装Gradle、ant或buck等构建工具。我在使用aapt2链接文件时遇到了一个问题 我正在使用aapt2将res文件夹中的所有文件编译成zip文件。但当我尝试将它们链接时,aapt2会抛出错误。 这些错误似乎是由于缺少app compat库造成的,我的问题是如何成功链接所有这些

我正在尝试编译一个我刚刚在Android Studio上的Kotlin中创建的Android应用程序,而不使用Gradle或任何其他构建工具。我的目的是加快编译应用程序的速度,而不必使用Android Studio或安装Gradle、ant或buck等构建工具。我在使用aapt2链接文件时遇到了一个问题

我正在使用aapt2将res文件夹中的所有文件编译成zip文件。但当我尝试将它们链接时,aapt2会抛出错误。 这些错误似乎是由于缺少app compat库造成的,我的问题是如何成功链接所有这些文件和kotlin文件以创建可部署的apk文件

下面将编译res文件夹中的所有文件并创建resources.zip文件

$AAPT compile --dir $APP_DIR/src/main/res -o $APP_DIR/build/intermediate/resources.zip    
然而,这是失败的

$AAPT link -o $APP_DIR/build/intermediate/ -I $PLATFORM $APP_DIR/build/intermediate/resources.zip --manifest $APP_DIR/src/main/AndroidManifest.xml
有以下错误

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.
错误:链接引用失败

这似乎是由于缺少app compat库造成的。我已尝试手动下载appcompat-v7-27.1.1.aar文件并将其链接,但此操作失败

如果有人找到了解决办法,请告诉我。谢谢

我想复制aapt2在这里提供的功能

实际上,使用额外的支持库是非常困难和混乱的,您会遇到这些错误,因为您使用的是支持库的主题,它不是android.jar的一部分,相反,您可以使用android.jar的默认主题。 放

代替

public  class MainActivity extends AppCompatActivity {...}
并将清单的应用程序主题更改为“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>
这篇参考文章非常有助于您的具体操作,还可以签署您的APK以便在设备上运行您的应用程序,否则在安装时可能会显示错误。
谢谢。

请使用下面的链接作为使用aapt/appt2编译java应用程序的参考,这样您就可以自己制作一个用于编译kotlin的应用程序了


我怀疑这会“加速编译应用程序”。Gradle在避免不必要的编译方面做得很好。在哪一部分你认为你可以做得更快?加速部分是值得怀疑的,我同意。我只是想看看我是否可以不用Gradle来做我正在做的项目。我的计划是将gradle拉入的依赖项预下载到一个文件夹中,并在aapt2链接阶段添加它们,以创建一个中间apk文件,然后我可以将其与kotlin二进制文件合并。
<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>
android:theme="@style/AppTheme"