I'm attempting to build an android project's data without using gradle for educational, portability and efficiency reasons (both in running the build and setting it up). My project doesn't require the heavyweight build processes in gradle as it's 99% a C++ project built with make. I also wish to understand the underlying processes better and I find gradle hides these.
I'm using AAPT (should I be using AAPT2?) and need to include an existing library's resources. I've learned that I need to use '-S' for these and I've been experimenting with the ordering of those parameters - each order gives different errors.
My batch file (I'm working on Windows ATM) currently looks like this:
echo off
set PROJ_DIR=%cd%
set BUILDTOOLSDIR=%ANDROID_SDK_ROOT%\build-tools\32.0.0
echo PROJ_DIR is %PROJ_DIR%
echo BUILD_TOOLS_DIR is %BUILDTOOLSDIR%
echo on
%BUILDTOOLSDIR%\aapt.exe package --non-constant-id -m -f ^
-M %PROJ_DIR%\AndroidManifest.xml ^
-I %ANDROID_SDK_ROOT%\platforms\android-32\android.jar ^
-P %PROJ_DIR%\libs\android-support-v7-appcompat.jar ^
-S C:\prog\libs\android\android-support-v7-appcompat\res\
-S %PROJ_DIR%\res ^
-J %PROJ_DIR%\src ^
--generate-dependencies ^
--auto-add-overlay
And I'm getting the following errors:
android-build\AndroidManifest.xml:9: error: Error: No resource found that matches the given name (at 'icon' with value '#mipmap/ic_launcher').
android-build\AndroidManifest.xml:9: error: Error: No resource found that matches the given name (at 'label' with value '#string/app_name').
android-build\AndroidManifest.xml:9: error: Error: No resource found that matches the given name (at 'roundIcon' with value '#mipmap/ic_launcher_round').
android-build\AndroidManifest.xml:9: error: Error: No resource found that matches the given name (at 'theme' with value '#style/AppTheme').
Those resources appear to exist, although I'm not sure how AAPT selects between the various resolution and shape variants I have. My 'res' directory looks like this:
drawable
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-v24
layout
mipmap-anydpi-v26
mipmap-hdpi
mipmap-mdpi
mipmap-xhdpi
mipmap-xxhdpi
mipmap-xxxhdpi
values
If I swap the order of the '-S' directories (I gather one of them is considered 'primary' and others 'overlays'), I get the following errors:
\res\values\styles.xml:8: error: Error: No resource found that matches the given name: attr 'colorAccent'.
\res\values\styles.xml:6: error: Error: No resource found that matches the given name: attr 'colorPrimary'.
\res\values\styles.xml:7: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.
\res\values\styles.xml:10: error: Error: No resource found that matches the given name: attr 'windowNoTitle'.
However, all of those colour definitions are present in '\res\values\color.xml'
These errors caused me to swap the -S directories around to an order I thought was probably incorrect in the first place, which removed the colour errors but produced the icon errors.
My question is why are these linking errors occurring when the files all appear to be in place? Are there any more general tips for hand-coding calls to AAPT (or AAPT2) or obvious mistakes I'm making in my AAPT call?
%BUILDTOOLSDIR%\aapt.exe package -f ^
-M %PROJ_DIR%\AndroidManifest.xml ^
-S %PROJ_DIR%\res ^
-S C:\prog\libs\android\android-support-v7-appcompat\res\ ^
-I %ANDROID_CP% ^
-I %ANDROID_SDK_ROOT%\platforms\android-32\android.jar ^
-S %PROJ_DIR%\res ^
-J %PROJ_DIR%\src ^
-F %APK_BASENAME%.apk.unaligned ^
--generate-dependencies ^
--auto-add-overlay
In the end, this worked and I removed references to the colour themes as I wasn't using them anyway. APK still doesn't run correctly (cannot find a class that is clearly right there) but it's dalvikified, aligned, signed and on the device.
Related
Build android app from command line without gradle, I tried the following article and working for simple Android App.
How to make Android apps without IDE from command line
But failed while trying with AppCompat layout, tried the following command line but still no luck
aapt package --auto-add-overlay -f -m -J $SRC_BASE/build/gen/java -M $SRC_BASE/src/AndroidManifest.xml -S $SRC_BASE/src/res -S /path/to/appcompat/v1.2.0/res -I /android-home/platforms/android-23/android.jar
ERROR: (using android-23)
/path/to/appcompat/v1.2.0/res/values-v24/values-v24.xml:3: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
/path/to/appcompat/v1.2.0/res/values-v24/values-v24.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
/path/to/appcompat/v1.2.0/res/values-v26/values-v26.xml:15: error: Error: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
even I tried with android-30.
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:9: error: No resource identifier found for attribute 'layout_constraintBottom_toTopOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:9: error: No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:9: error: No resource identifier found for attribute 'layout_constraintRight_toRightOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:9: error: No resource identifier found for attribute 'layout_constraintTop_toTopOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:20: error: No resource identifier found for attribute 'layout_constraintTop_toBottomOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:20: error: No resource identifier found for attribute 'layout_constraintBottom_toTopOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:20: error: No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:20: error: No resource identifier found for attribute 'layout_constraintRight_toRightOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:31: error: No resource identifier found for attribute 'layout_constraintTop_toBottomOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:31: error: No resource identifier found for attribute 'layout_constraintBottom_toBottomOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:31: error: No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:31: error: No resource identifier found for attribute 'layout_constraintRight_toRightOf' in package 'my.pkg.tst'
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:9: error: Error: No resource found that matches the given name (at 'layout_constraintBottom_toTopOf' with value '#id/tv2').
${PROJECT_BASE_DIR}/src/res/layout/activity_main.xml:20: error: Error: No resource found that matches the given name (at 'layout_constraintBottom_toTopOf' with value '#id/tv3').
/path/to/appcompat/v1.2.0/res/color/abc_btn_colored_borderless_text_material.xml:20: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_btn_colored_text_material.xml:20: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_btn_checkable.xml:19: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_default.xml:19: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_edittext.xml:19: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_seek_thumb.xml:19: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_spinner.xml:19: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_switch_track.xml:19: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_switch_track.xml:20: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
/path/to/appcompat/v1.2.0/res/color/abc_tint_switch_track.xml:21: error: No resource identifier found for attribute 'alpha' in package 'my.pkg.tst'
Anybody have success with AppCompat and other libraries without gradle, only using pure java, and android sdk tools ? (ant is also fine.)
Build the android app without gradle for simple app without app-compat. The following code is working fine for simple android app.(reference for if anyone interested.)
mkdir -p ${PROJECT_BASE_DIR}/build/gen/java
aapt package -f -m -J ${PROJECT_BASE_DIR}/build/gen/java -M ${PROJECT_BASE_DIR}/src/AndroidManifest.xml -S ${PROJECT_BASE_DIR}/src/res -I ${ANDROID_SDK_HOME}/platforms/android-30/android.jar
mkdir -p ${PROJECT_BASE_DIR}/build/classes
javac -d ${PROJECT_BASE_DIR}/build/classes -source 1.7 -target 1.7 -classpath ${PROJECT_BASE_DIR}/src/java:${PROJECT_BASE_DIR}/build/gen/java -bootclasspath ${ANDROID_SDK_HOME}/platforms/android-30/android.jar ${PROJECT_BASE_DIR}/src/java/jj/android/clb/MainClass.java
dx --dex --output=${PROJECT_BASE_DIR}/build/classes.dex ${PROJECT_BASE_DIR}/build/classes
aapt package -f -m -F ${PROJECT_BASE_DIR}/build/app.unaligned.apk -M ${PROJECT_BASE_DIR}/src/AndroidManifest.xml -S ${PROJECT_BASE_DIR}/src/res -I ${ANDROID_SDK_HOME}/platforms/android-30/android.jar
cd ${PROJECT_BASE_DIR}/build
aapt add ${PROJECT_BASE_DIR}/build/app.unaligned.apk classes.dex
'classes.dex'...
cd ..
zipalign -f 4 build/app.unaligned.apk build/app.aligned.apk
apksigner sign --ks Andorid-KeyStore.jks --in build/app.aligned.apk --out build/app.sign.apk
I'm manually compiling an apk. But there is an error in packaging when using aapt.
Create a simple project in Android Studio. Then use aapt to package his resources。
The command is shown below:
aapt package -f -m -J build -S res -M AndroidManifest.xml
-I /SDK/platforms/android-28/android.jar
The error output is as follows:
error: resource style/Theme.AppCompat.Light.NoActionBar (aka com.jz.myapplication:style/Theme.AppCompat.Light.NoActionBar) not found.
./res/values/styles.xml:6: error: style attribute 'attr/colorPrimary (aka com.jz.myapplication:attr/colorPrimary)' not found.
./res/values/styles.xml:7: error: style attribute 'attr/colorPrimaryDark (aka com.jz.myapplication:attr/colorPrimaryDark)' not found.
./res/values/styles.xml:8: error: style attribute 'attr/colorAccent (aka com.jz.myapplication:attr/colorAccent)' not found.
error: failed linking references.
You are missing resources from the app compat library.
If you're going to use resources from some libraries, you need to include all of the resources from these libraries and their transitive dependencies using the -S flag. You also need to be mindful of the order of these inputs as they will impact the resource overrides at run-time.
If you use the Android Gradle Plugin instead all of this will be done automatically for you.
I'm trying to build my first android project from Unity..
CommandInvokationFailure: Failed to re-package resources.
..\tools_r25.2.3-windows\build-tools\27.0.3\aapt.exe package
--auto-add-overlay -v -f -m -J "gen" -M "AndroidManifest.xml" -S "res" -I "../tools_r25.2.3-windows\platforms\android-23\android.jar" -F bin/resources.ap_
stderr[ AndroidManifest.xml:4: error: Error: No resource found that
matches the given name (at 'theme' with value
'#style/UnityThemeSelector').
AndroidManifest.xml:4: error: Error: No resource found that matches
the given name (at 'icon' with value '#drawable/app_icon').
AndroidManifest.xml:4: error: Error: No resource found that matches
the given name (at 'label' with value '#string/app_name').
AndroidManifest.xml:4: error: Error: No resource found that matches
the given name (at 'banner' with value '#drawable/app_banner').
AndroidManifest.xml:5: error: Error: No resource found that matches
the given name (at 'label' with value '#string/app_name').
] stdout[ Configurations: (default)
Files: AndroidManifest.xml
Src: () AndroidManifest.xml
I'm aware of the fact that I'm not the first to have a similar error, yet I've not bean able to fix this yet and would appreciate any help.
Thanks
I am trying to run a command via aapt to test out the functionality.
./aapt package -f --no-crunch
-M /home/username/AndroidStudioProjects/ProjectName/androidTest/src/main/AndroidManifest.xml
-I /home/username/Android/Sdk/platforms/android-27/android.jar
-S /home/username/AndroidStudioProjects/ProjectName/androidTest/build/intermediates/res/merged/androidTest/debug/
But I get this weird error message.
invalid resource directory name: /home/username/AndroidStudioProjects/ProjectName/androidTest/build/intermediates/res/merged/androidTest/debug/ drawable-xhdpi-v4_abc_list_selector_disabled_holo_dark.9.png.flat
invalid resource directory name: /home/username/AndroidStudioProjects/ProjectName/androidTest/build/intermediates/res/merged/androidTest/debug/ drawable_abc_ic_go_search_api_material.xml.flat
invalid resource directory name: /home/username/AndroidStudioProjects/ProjectName/androidTest/build/intermediates/res/merged/androidTest/debug/ drawable-xxxhdpi-v4_abc_scrubber_control_to_pressed_mtrl_005.png.flat
invalid resource directory name: /home/username/AndroidStudioProjects/ProjectName/androidTest/build/intermediates/res/merged/androidTest/debug/ color_abc_primary_text_material_light.xml.flat
invalid resource directory name: /home/username/AndroidStudioProjects/ProjectName/androidTest/build/intermediates/res/merged/androidTest/debug/ drawable-mdpi-v4_abc_btn_check_to_on_mtrl_000.png.flat
ERROR: Invalid BCP 47 tag in directory name b+sr+latn_values
And so forth like this.
I am using Gradle 3.0.1 to build the project. What causes this error ?
Gradle 3.0.1 doesn't uses aapt it uses aapt2 by default. The build process is different for both of these.More details in this link.
aapt2 can be disabled my adding android.enableAapt2=false in gradle.properties file.
I integrated Grow Compete, Grow Spend and Grow Ultimate modules to my Unity Project. When I tried to make build the project, I receive two errors that says :
CommandInvokationFailure: Failed to re-package resources. See the Console for details.
C:\Users\halil.cosgun\Desktop\ADTBundle\adt_bundle\sdk\build-tools\21.1.1\aapt.exe
package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S
"res" -I
"C:/Users/halil.cosgun/Desktop/ADTBundle/adt_bundle/sdk\platforms\android-21\android.jar"
-F bin/resources.ap_ --extra-packages com.google.android.gms -S "C:\Users\halil.cosgun\Desktop\SoomlaWorkout\SoomlaWorkout\Temp\StagingArea\android-libraries\google-play-services_lib\res"
stderr[ res\drawable\common_signin_btn_icon_dark 1.xml: Invalid file
name: must contain only [a-z0-9_.]
res\drawable\common_signin_btn_icon_dark 2.xml: Invalid file name:
must contain only [a-z0-9_.] res\drawable\common_signin_btn_icon_light
... ...
res\drawable-mdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-hdpi-v4\common_signin_btn_icon_focus_dark.11.png:0:
error: Resource entry common_signin_btn_icon_focus_dark is already
defined.
res\drawable-hdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-xhdpi-v4\common_signin_btn_icon_focus_dark.11.png:0:
error: Resource entry common_signin_btn_icon_focus_dark is already
defined.
res\drawable-xhdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-xxhdpi-v4\common_signin_btn_icon_focus_dark.11.png:0:
error: Resource entry common_signin_btn_icon_focus_dark is already
defined.
res\drawable-xxhdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-mdpi-v4\common_signin_btn_icon_focus_dark.9.png:0: error:
Resource entry common_signin_btn_icon_focus_dark is already defined.
res\drawable-mdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\draw
And
Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details.
C:\Users\halil.cosgun\Desktop\ADTBundle\adt_bundle\sdk\build-tools\21.1.1\aapt.exe
package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S
"res" -I
"C:/Users/halil.cosgun/Desktop/ADTBundle/adt_bundle/sdk\platforms\android-21\android.jar"
-F bin/resources.ap_ --extra-packages com.google.android.gms -S "C:\Users\halil.cosgun\Desktop\SoomlaWorkout\SoomlaWorkout\Temp\StagingArea\android-libraries\google-play-services_lib\res"
stderr[ res\drawable\common_signin_btn_icon_dark 1.xml: Invalid file
name: must contain only [a-z0-9_.]
res\drawable\common_signin_btn_icon_dark 2.xml: Invalid file name:
must contain only [a-z0-9_.] res\drawable\common_signin_btn_icon_light
1.xml: Invalid file name: must contain only [a-z0-9_.] res\drawable\common_signin_btn_icon_light 2.xml: Invalid file name:
must contain only [a-z0-9_.] res\drawable\common_signin_btn_text_dark
1.xml: Invalid file name: must contain only [a-z0-9_.] res\drawable\common_signin_btn_text_dark 2.xml: Invalid file name:
must contain only [a-z0-9_.] res\drawable\common_signin_btn_text_light
1.xml: Invalid file name: must contain only [a-z0-9_.] res\drawable\common_signin_btn_text_light 2.xml: Invalid file name:
must contain only [a-z0-9_.]
res\drawable-mdpi-v4\ic_plusone_medium_off_client 1.png: Invalid file
name: must contain only [a-z0-9_.]
res\drawable-hdpi-v4\ic_plusone_medium_off_client 1.png: Invalid file
name: must contain only [a-z0-9_.]
res\drawable-xhdpi-v4\ic_plusone_medium_off_client 1.png: Invalid file
name: must contain only [a-z0-9_.]
res\drawable-xxhdpi-v4\ic_plusone_medium_off_client 1.png: Invalid
file name: must contain only [a-z0-9_.]
... ...
res\drawable-hdpi-v4\common_signin_btn_icon_focus_dark.11.png:0:
error: Resource entry common_signin_btn_icon_focus_dark is already
defined.
res\drawable-hdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-xhdpi-v4\common_signin_btn_icon_focus_dark.11.png:0:
error: Resource entry common_signin_btn_icon_focus_dark is already
defined.
res\drawable-xhdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-xxhdpi-v4\common_signin_btn_icon_focus_dark.11.png:0:
error: Resource entry common_signin_btn_icon_focus_dark is already
defined.
res\drawable-xxhdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally defined here.
res\drawable-mdpi-v4\common_signin_btn_icon_focus_dark.9.png:0: error:
Resource entry common_signin_btn_icon_focus_dark is already defined.
res\drawable-mdpi-v4\common_signin_btn_icon_focus_dark.10.png:0:
Originally
Could you please help me.
Thanks for your time.