实际上,我正在关注一篇文章,该文章显示了如何在dx.bat和aapt.exe工具的帮助下在命令行上生成APK文件(链接到artical-https://geosoft.no/development/android.html),我生成了R.java编译的主Activity,然后继续执行文章生成的APK文件中给出的进一步步骤,但apk未在设备上安装,表明应用程序已损坏(可能是由于清单文件的方式过时,因为文章似乎已过时而弃用),但成功生成了apk文件。现在我正在尝试将android studio项目与上述文章步骤合并。我生成了Android Studio空项目,我在正确的位置替换了清单文件。我将android Studio项目中的Activity.main替换为位置,配置了文件中的更改,并按照之前生成apk的文章中的描述运行了aapt命令,现在我再次使用新的清单文件,源文件和资源文件运行该命令从android studio项目生成R.java文件,如文章中所述
C:/Users/x/AppData/Local/Android/Sdk/build-tools/26.0.2/aapt package -v -f -m -S D:/JavaCompilerJava/testbyaapt2/AndroidTest/res -J D:/JavaCompilerJava/testbyaapt2/AndroidTest/src -M D:/JavaCompilerJava/testbyaapt2/AndroidTest/AndroidManifest.xml -I C:/Users/x/AppData/Local/Android/Sdk/platforms/android-7/android.jar
现在这一次命令输出在R.java中生成id时出现一些错误-
C:/Users/x/AppData/Local/Android/Sdk/build-tools/26.0.2/aapt package -v -f -m -S D:/JavaCompilerJava/testbyaapt2/AndroidTest/res -J D:/JavaCompilerJava/testbyaapt2/AndroidTest/src -M D:/JavaCompilerJava/testbyaapt2/AndroidTest/AndroidManifest.xml -I C:/Users/Rx/AppData/Local/Android/Sdk/platforms/android-7/android.jar
Configurations:
(default)
v24
mdpi-v4
hdpi-v4
xhdpi-v4
xxhdpi-v4
xxxhdpi-v4
anydpi-v26
Files:
drawable\ic_launcher_background.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\drawable\ic_launcher_background.xml
drawable\ic_launcher_foreground.xml
Src: (v24) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\drawable-v24\ic_launcher_foreground.xml
layout\activity_main.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\layout\activity_main.xml
mipmap\ic_launcher.png
Src: (mdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-mdpi\ic_launcher.png
Src: (hdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-hdpi\ic_launcher.png
Src: (xhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xhdpi\ic_launcher.png
Src: (xxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxhdpi\ic_launcher.png
Src: (xxxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxxhdpi\ic_launcher.png
mipmap\ic_launcher.xml
Src: (anydpi-v26) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-anydpi-v26\ic_launcher.xml
mipmap\ic_launcher_round.png
Src: (mdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-mdpi\ic_launcher_round.png
Src: (hdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-hdpi\ic_launcher_round.png
Src: (xhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xhdpi\ic_launcher_round.png
Src: (xxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxhdpi\ic_launcher_round.png
Src: (xxxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxxhdpi\ic_launcher_round.png
mipmap\ic_launcher_round.xml
Src: (anydpi-v26) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-anydpi-v26\ic_launcher_round.xml
values\colors.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\colors.xml
values\strings.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\strings.xml
values\styles.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\styles.xml
AndroidManifest.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\AndroidManifest.xml
Resource Dirs:
Type drawable
drawable\ic_launcher_background.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\drawable\ic_launcher_background.xml
drawable\ic_launcher_foreground.xml
Src: (v24) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\drawable-v24\ic_launcher_foreground.xml
Type layout
layout\activity_main.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\layout\activity_main.xml
Type mipmap
mipmap\ic_launcher.png
Src: (mdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-mdpi\ic_launcher.png
Src: (hdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-hdpi\ic_launcher.png
Src: (xhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xhdpi\ic_launcher.png
Src: (xxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxhdpi\ic_launcher.png
Src: (xxxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxxhdpi\ic_launcher.png
mipmap\ic_launcher.xml
Src: (anydpi-v26) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-anydpi-v26\ic_launcher.xml
mipmap\ic_launcher_round.png
Src: (mdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-mdpi\ic_launcher_round.png
Src: (hdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-hdpi\ic_launcher_round.png
Src: (xhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xhdpi\ic_launcher_round.png
Src: (xxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxhdpi\ic_launcher_round.png
Src: (xxxhdpi-v4) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxxhdpi\ic_launcher_round.png
mipmap\ic_launcher_round.xml
Src: (anydpi-v26) D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-anydpi-v26\ic_launcher_round.xml
Type values
values\colors.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\colors.xml
values\strings.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\strings.xml
values\styles.xml
Src: () D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\styles.xml
Including resources from package: C:\Users\x\AppData\Local\Android\Sdk\platforms\android-7\android.jar
applyFileOverlay for drawable
applyFileOverlay for layout
applyFileOverlay for anim
applyFileOverlay for animator
applyFileOverlay for interpolator
applyFileOverlay for transition
applyFileOverlay for xml
applyFileOverlay for raw
applyFileOverlay for color
applyFileOverlay for menu
applyFileOverlay for font
applyFileOverlay for mipmap
(new resource id ic_launcher_background from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\drawable\ic_launcher_background.xml)
(new resource id ic_launcher_foreground from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\drawable-v24\ic_launcher_foreground.xml)
(new resource id ic_launcher from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-mdpi\ic_launcher.png)
(new resource id ic_launcher from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-hdpi\ic_launcher.png)
(new resource id ic_launcher from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xhdpi\ic_launcher.png)
(new resource id ic_launcher from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxhdpi\ic_launcher.png)
(new resource id ic_launcher from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxxhdpi\ic_launcher.png)
(new resource id ic_launcher from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-anydpi-v26\ic_launcher.xml)
(new resource id ic_launcher_round from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-mdpi\ic_launcher_round.png)
(new resource id ic_launcher_round from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-hdpi\ic_launcher_round.png)
(new resource id ic_launcher_round from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xhdpi\ic_launcher_round.png)
(new resource id ic_launcher_round from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxhdpi\ic_launcher_round.png)
(new resource id ic_launcher_round from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-xxxhdpi\ic_launcher_round.png)
(new resource id ic_launcher_round from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\mipmap-anydpi-v26\ic_launcher_round.xml)
(new resource id activity_main from D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\layout\activity_main.xml)
D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\styles.xml:8: error: Error: No resource found that matches the given name: attr 'colorAccent'.
D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\styles.xml:6: error: Error: No resource found that matches the given name: attr 'colorPrimary'.
D:\JavaCompilerJava\testbyaapt2\AndroidTest\res\values\styles.xml:7: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.
C:\Users\x>
如您所见,Styles.xml中有关App主题的结尾处有资源错误,因此不会创建R.java文件。 可能是AAPT无法获得附加资源APP主题父资源值的原因。 这可能是Android Studio主题values / style.xml中的Activity参考正在使用应用主题的x.aar库的一些其他库目录的原因。在android studio中通过右键单击styles.xml文件> goto> declaration>中的Theme.AppCompat.Light.DarkActionBar进行检查时,它将在Windows System的AppData中的.gradle中使用一些附加的values.xml目录。文章的清单文件(上面给出的链接)与Android Studio生成的清单文件之间也存在一些差异,即Android Studio清单文件包含App Theme,这会导致生成R.java文件时出错。我只是想解决如何使用从android studio项目合并的新文件生成R.java文件,以生成dex文件,并进一步生成apk文件。我可以提供有关解决此问题的任何其他信息或文件。 希望我能得到帮助。 谢谢。