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.
Related
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.
I'm trying to build tensorflow for android. I'd like to use the DecodeJpeg op on android. Hence I've added the file, decode_image_op.cc, in which it is declared to build file.
This is the command I run to build tensorflow
bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=#bazel_tools//tools/cpp:toolchain --cpu=arm64-v8a
This throws the following error
ERROR: /tensorflow/core/kernels/BUILD:4950:1: undeclared inclusion(s) in rule '//tensorflow/core/kernels:android_tensorflow_kernels':
this rule is missing dependency declarations for the following files included by 'tensorflow/core/kernels/decode_image_op.cc':
'/tensorflow/core/lib/jpeg/jpeg_mem.h'
'/tensorflow/core/platform/jpeg.h'
Where should I add these header files to resolve this error?
It looks like you can add the cc_library target //tensorflow/core/kernels:android_tensorflow_image_op in the deps attribute of the cc_binary target //tensorflow/contrib/android:libtensorflow_inference.so.
//tensorflow/core/kernels:android_tensorflow_image_op already defines decode_image_op.cc and its dependencies.
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'm trying to use Theme from AppCompat as parent for mine but seems like I am unable to include resources.
eg:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
</style>
</resources>
gives me an error:
Error:Execution failed for task ':processDebugResources'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
G:\Android\android-studio\sdk\build-tools\19.0.3\aapt.exe package -f --no-crunch -I G:\Android\android-studio\sdk\platforms\android-19\android.jar -M E:\Studio\Git\face_rec_android\build\manifests\debug\AndroidManifest.xml -S E:\Studio\Git\face_rec_android\build\res\all\debug -A E:\Studio\Git\face_rec_android\build\assets\debug -m -J E:\Studio\Git\face_rec_android\build\source\r\debug -F E:\Studio\Git\face_rec_android\build\libs\face_rec_android-debug.ap_ --debug-mode --custom-package in.amolgupta.helpingfaceless
Error Code:
1
Output:
E:\Studio\myapp\build\res\all\debug\values\values.xml:127: error: Error retrieving parent for item: No resource found that matches the given name '#style/Theme.AppCompat.Light.DarkActionBar'.
I have tried including the jar file which apparently doesn't have resources but mainly played around with build.gradle like
dependencies {
compile 'com.android.support:appcompat-v7:19.1.+'
}
Any way I can make this work?
Couldn't import as module from extra because of there was no build.gradle file there.
You need to download this lib from SDK Manager which placed in Android SDK folder then go to the sdk folder/extras/android/v7/ find .jar lib file and put this file into library folder of your project.
I tried to run rake run:android the follwing occurs, kindly assist me.
AndroidManifest change file [C:/Users/giridhran/workspace/myfirst/bin/libs/relea
se/arm-linux-androideabi/4.4.3/extensions/AndroidManifest.xml] from native exten
sion not found !
delete original manifest
Manifest updated by extension saved!
EXT: add additional files to project before build
PWD: C:/RhoStudio/ruby/lib/ruby/gems/1.8/gems/rhodes-3.3.2
CMD: D:/installer/android-sdk_r11-windows/android-sdk-windows/platform-tools/aap
t.exe package -f -M C:/Users/giridhran/workspace/myfirst/bin/tmp/AndroidManifest
.xml -S C:/Users/giridhran/workspace/myfirst/bin/tmp/res -A C:/RhoStudio/ruby/li
b/ruby/gems/1.8/gems/rhodes-3.3.2/platform/android/Rhodes/assets -I D:/installer
/android-sdk_r11-windows/android-sdk-windows/platforms/android-8/android.jar -J
C:/Users/giridhran/workspace/myfirst/bin/tmp
C:\Users\giridhran\workspace\myfirst\bin\tmp\AndroidManifest.xml:30: error: No r
esource identifier found for attribute 'xlargeScreens' in package 'android'
Error in AAPT
Before running rake run:android command, please ensure that:
you have set the path of java-bin folder.
you have set the path of Android SDK & NDK.
check the android version in build.xml file.