Android resource linking failed AAPT: unknown option '--proguard-minimal-keep-rules' - android

My Android Studio was working fine, everything was good but after updating Android Studio to the latest version and updating gradle I got the following error
Could you please provide the solution, thank you
Task :app:processDebugResources FAILED
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{}],"original":"AAPT: unknown option '--proguard-minimal-keep-rules'.\n\naapt2 link [options] -o arg --manifest arg files...\n\nOptions:\n -o arg Output path.\n --manifest arg Path to the Android manifest to build.\n -I arg Adds an Android APK to link against.\n -A arg An assets directory to include in the APK. These are unprocessed.\n -R arg Compilation unit to link, using overlay semantics.\n The last conflicting resource given takes precedence.\n --package-id arg Specify the package ID to use for this app. Must be greater or equal to\n 0x7f and can't be used with --static-lib or --shared-lib.\n --java arg Directory in which to generate R.java.\n --proguard arg Output file for generated Proguard rules.\n --proguard-main-dex arg Output file for generated Proguard rules for the main dex.\n --proguard-conditional-keep-rules Generate conditional Proguard keep rules.\n --no-auto-version Disables automatic style and layout SDK versioning.\n --no-version-vectors Disables automatic versioning of vector drawables. Use this only\n when building with vector drawable support library.\n --no-version-transitions Disables automatic versioning of transition resources. Use this only\n when building with transition support library.\n --no-resource-deduping Disables automatic deduping of resources with\n identical values across compatible configurations.\n --enable-sparse-encoding This decreases APK size at the cost of resource retrieval performance.\n -x Legacy flag that specifies to use the package identifier 0x01.\n -z Require localization of strings marked 'suggested'.\n -c arg Comma separated list of configurations to include. The default\n is all configurations.\n --preferred-density arg Selects the closest matching density and strips out all others.\n --product arg Comma separated list of product names to keep\n --output-to-dir Outputs the APK contents to a directory specified by -o.\n --no-xml-namespaces Removes XML namespace prefix and URI information\n from AndroidManifest.xml and XML binaries in res/*.\n --min-sdk-version arg Default minimum SDK version to use for AndroidManifest.xml.\n --target-sdk-version arg Default target SDK version to use for AndroidManifest.xml.\n --version-code arg Version code (integer) to inject into the AndroidManifest.xml if none is\n present.\n --version-code-major arg Version code major (integer) to inject into the AndroidManifest.xml if none is\n present.\n --version-name arg Version name to inject into the AndroidManifest.xml if none is present.\n --replace-version If --version-code and/or --version-name are specified, these\n values will replace any value already in the manifest. By\n default, nothing is changed if the manifest already defines\n these attributes.\n --compile-sdk-version-code arg Version code (integer) to inject into the AndroidManifest.xml if none is\n present.\n --compile-sdk-version-name arg Version name to inject into the AndroidManifest.xml if none is present.\n --shared-lib Generates a shared Android runtime library.\n --static-lib Generate a static Android library.\n --proto-format Generates compiled resources in Protobuf format.\n Suitable as input to the bundle tool for generating an App Bundle.\n --no-static-lib-packages Merge all library resources under the app's package.\n --non-final-ids Generates R.java without the final modifier. This is implied when\n --static-lib is specified.\n --stable-ids arg File containing a list of name to ID mapping.\n --emit-ids arg Emit a file at the given path with a list of name to ID mappings,\n suitable for use with --stable-ids.\n --private-symbols arg Package name to use when generating R.java for private symbols.\n If not specified, public and private symbols will use the application's\n package name.\n --custom-package arg Custom Java package under which to generate R.java.\n --extra-packages arg Generate the same R.java but with different package names.\n --add-javadoc-annotation arg Adds a JavaDoc annotation to all generated Java classes.\n --output-text-symbols arg Generates a text file containing the resource symbols of the R class in\n the specified folder.\n --allow-reserved-package-id Allows the use of a reserved package ID. This should on be used for\n packages with a pre-O min-sdk\n \n --auto-add-overlay Allows the addition of new resources in overlays without\n tags.\n --rename-manifest-package arg Renames the package in AndroidManifest.xml.\n --rename-instrumentation-target-package arg Changes the name of the target package for instrumentation. Most useful\n when used in conjunction with --rename-manifest-package.\n -0 arg File extensions not to compress.\n --no-compress Do not compress any resources.\n --warn-manifest-validation Treat manifest validation errors as warnings.\n --split arg Split resources matching a set of configs out to a Split APK.\n Syntax: path/to/output.apk:[,[...]].\n On Windows, use a semicolon ';' separator instead.\n -v Enables verbose logging.\n --debug-mode Inserts android:debuggable=\"true\" in to the application node of the\n manifest, making the application debuggable even on production devices.\n --strict-visibility Do not allow overlays with different visibility levels.\n -h Displays this help menu\n\n ","tool":"AAPT"}
AAPT: unknown option '--proguard-minimal-keep-rules'.
aapt2 link [options] -o arg --manifest arg files...
Options:
-o arg Output path.
--manifest arg Path to the Android manifest to build.
-I arg Adds an Android APK to link against.
-A arg An assets directory to include in the APK. These are unprocessed.
-R arg Compilation unit to link, using overlay semantics.
The last conflicting resource given takes precedence.
--package-id arg Specify the package ID to use for this app. Must be greater or equal to
0x7f and can't be used with --static-lib or --shared-lib.
--java arg Directory in which to generate R.java.
--proguard arg Output file for generated Proguard rules.
--proguard-main-dex arg Output file for generated Proguard rules for the main dex.
--proguard-conditional-keep-rules Generate conditional Proguard keep rules.
--no-auto-version Disables automatic style and layout SDK versioning.
--no-version-vectors Disables automatic versioning of vector drawables. Use this only
when building with vector drawable support library.
--no-version-transitions Disables automatic versioning of transition resources. Use this only
when building with transition support library.
--no-resource-deduping Disables automatic deduping of resources with
identical values across compatible configurations.
--enable-sparse-encoding This decreases APK size at the cost of resource retrieval performance.
-x Legacy flag that specifies to use the package identifier 0x01.
-z Require localization of strings marked 'suggested'.
-c arg Comma separated list of configurations to include. The default
is all configurations.
--preferred-density arg Selects the closest matching density and strips out all others.
--product arg Comma separated list of product names to keep
--output-to-dir Outputs the APK contents to a directory specified by -o.
--no-xml-namespaces Removes XML namespace prefix and URI information
from AndroidManifest.xml and XML binaries in res/*.
--min-sdk-version arg Default minimum SDK version to use for AndroidManifest.xml.
--target-sdk-version arg Default target SDK version to use for AndroidManifest.xml.
--version-code arg Version code (integer) to inject into the AndroidManifest.xml if none is
present.
--version-code-major arg Version code major (integer) to inject into the AndroidManifest.xml if none is
present.
--version-name arg Version name to inject into the AndroidManifest.xml if none is present.
--replace-version If --version-code and/or --version-name are specified, these
values will replace any value already in the manifest. By
default, nothing is changed if the manifest already defines
these attributes.
--compile-sdk-version-code arg Version code (integer) to inject into the AndroidManifest.xml if none is
present.
--compile-sdk-version-name arg Version name to inject into the AndroidManifest.xml if none is present.
--shared-lib Generates a shared Android runtime library.
--static-lib Generate a static Android library.
--proto-format Generates compiled resources in Protobuf format.
Suitable as input to the bundle tool for generating an App Bundle.
--no-static-lib-packages Merge all library resources under the app's package.
--non-final-ids Generates R.java without the final modifier. This is implied when
--static-lib is specified.
--stable-ids arg File containing a list of name to ID mapping.
--emit-ids arg Emit a file at the given path with a list of name to ID mappings,
suitable for use with --stable-ids.
--private-symbols arg Package name to use when generating R.java for private symbols.
If not specified, public and private symbols will use the application's
package name.
--custom-package arg Custom Java package under which to generate R.java.
--extra-packages arg Generate the same R.java but with different package names.
--add-javadoc-annotation arg Adds a JavaDoc annotation to all generated Java classes.
--output-text-symbols arg Generates a text file containing the resource symbols of the R class in
the specified folder.
--allow-reserved-package-id Allows the use of a reserved package ID. This should on be used for
packages with a pre-O min-sdk
--auto-add-overlay Allows the addition of new resources in overlays without
tags.
--rename-manifest-package arg Renames the package in AndroidManifest.xml.
--rename-instrumentation-target-package arg Changes the name of the target package for instrumentation. Most useful
when used in conjunction with --rename-manifest-package.
-0 arg File extensions not to compress.
--no-compress Do not compress any resources.
--warn-manifest-validation Treat manifest validation errors as warnings.
--split arg Split resources matching a set of configs out to a Split APK.
Syntax: path/to/output.apk:[,[...]].
On Windows, use a semicolon ';' separator instead.
-v Enables verbose logging.
--debug-mode Inserts android:debuggable="true" in to the application node of the
manifest, making the application debuggable even on production devices.
--strict-visibility Do not allow overlays with different visibility levels.
-h Displays this help menu

I had the same problem after updating AS and grade plugin, the problem is with Gradle version 6.1.1 try downgrading to the latest stable one from the project structure till the release of another Gradle version.
Go to -
file -> project structure

This is a common issue
Try these basic solutions:
(Check if it works after trying every solution)
File->Invalidate Cache and restart
Build -> clean project.
Delete the build folder from your code.
Make sure that you have updated all dependencies in the project-level Gradle
file.

Related

Android Studio - Gradle build

Default method desugaring of io.appium.java_client.DefaultGenericMobileDriver failed because its super class org.openqa.selenium.remote.RemoteWebDriver is missing
I get the above error continuously when I started running the android studio for the initial setup of gradle. I checked on web, they say that environment variables for JAVA and Android SDK has to be set fine. I did that already. Is there is something else I wanna do?
Check whether the environment variable set is correct by typing "Javac" in command prompt.
C:\Users\VISHAL>javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
#<filename> Read options and filenames from file
if the problem is still there then try rebuilding it under a decent network connection or try reinstalling it with any installation guide video avaliable on Youtube.

Android NDK path variable for "strip" command in CMake build tool chain

I am trying to add a strip debug symbols step for my Android library which includes native shared libraries for different ABIs, e.g. x86/native-lib.so, x86_64/native-lib.so, arm64-v8a/native-lib.so, etc.
I understand that the strip command must be respective to each ABI. So, I need to invoke the correct strip command, for which I need to know its correct path during build time.
For example, for ABI x86_64, I need to have below path setting:
set(STRIP ~/Library/Android/android-ndk-r16b/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip)
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND ${STRIP}
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
The path I need is illustrated like below:
So, my questions are:
Is there an existing CMake variable to point at this path, i.e. /android-ndk-r16b/toolchains/???/prebuilt/???/bin/???-???-???-strip?
If not, is there a way to form this path utilising other known Android CMake variable, e.g. ANDROID_NDK, ANDROID_ABI, etc?
Thanks #Alex Cohn a lot for pointing out the file android.toolchain.cmake which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake, from command line to the build process. Because, this file, i.e. android.toolchain.cmake, was already taken into account automatically by Android native build system.
You can use ${CMAKE_STRIP}. It is set appropriately when you use -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.

How does Android maintain the linkage info between R constant and the actual file?

How does Android maintain the linkage info between R constant and the actual resource file?
For example,
setContentView(R.layout.activity);
R.layout.activity points to res/layout/activity.xml. R.layout.activity is stored in the R.java file, but where is this linkage info maintained?
The R class is generated by the aapt tool as can be seen in the header of the file R.java:
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
You can find the file in Android Studio by selecting an R symbol in your code and then selecting menu item Navigate | Declaration. The aapt tool is automatically run in the build process and also in response to file changes in the resources dir in order to give you up to date source code symbols.
If you mean to ask where the mapping between the constants for the layout files and the filenames is stored then I don't know if there is such a mapping. The aapt does more than just generate the R class. It also packages all those resources together. I expect that it packages them by resource Id and not by original filename.

How can I obfuscate XML resource files with DexGuard?

I am using to DexGuard to process my android applications.
On DexGuard's Homepage they say it features: XML resource obfuscation
I already tested DexGuard and decompiled my output .apks with apktool.
The problem is ALL resource files are decompiled succesffully, so they have not been obfuscated apparently.
Now my question is, does DexGuard automatically obfuscate XML resources or do i have to activate it somehow in my dexguard-project.txt file?
Is it possible to obfuscate XML resources like strings.xml or am I misunderstanding this feature?
Why do you want to obfuscate strings.xml? is it because you have api keys or oauth secrets in there? If so, then better to move them to assets/config.properties file and load to a java.util.Properties object like this...
Properties appConfigProperties = new Properties();
appConfigProperties.load(context.getAssets().open("config.properties"))
String myApiKey = appConfigProperties.get("my_api_key");
(for brevity I've removed the exception handling)
Be sure to enable asset encryption in your DexGuard config file:
-encryptassetfiles assets/**
I received the following statement from DexGuard:
Resource XML files are obfuscated automatically in release builds,
although the differences may be subtle. You can compare the
differences with for instance aapt d xmltree application.apk
AndroidManifest.xml. We are working on more obfuscation of resources
for upcoming versions.
After executing the proposed command aapt d xmltree application.apk (where application.apk is a simple HelloWorld Application) i finally could see what DexGuard actually obfuscates in XML files:
Each attribute in an XML resource file is identified by a name, but often also by a numeric identifier.
 In AndroidManifest.xml for example:
android:versionName(0x010102lc) = "1.0"
In the obfuscation step, DexGuard can remove the name of an attribute, but only if this attribute also has a numeric identifier.
After DexGuard obfuscation the above attribute will look like this:
:(0x010102lc) = "1.0"
As XML elements of strings.xml for instance only have a name and no numeric identifier, there won't be any differences in the decompiled XML file.

Why is aapt not adding `<values/>` in the apk?

I am using Titanium which is a cross-platform development Tool. Titanium uses it own building script to create the apk.
I have a Titanium application that uses a native module : a Java library that makes VOIP calls. The Java application works, and when I create a Titanium application with an empty module, it works.
But I have a build problem using a module based on the VOIP module inside the Titanium application : some Resources are missing in the apk.
First the build system merges some Resources from our Titanium application and some native android modules and put them in a directory build. I have for exemple : build/android/res/values/strings.xml file where all keys and values seems ok and valid xml.
Then the build calls aapt and create the apk using also the Titanium Resources for library widgets (ex: strings for notifications). And in this apk, the build/android/res/values/strings.xml is missing. It doesn't exists. The application starts, the VOIP service starts, and then it's crashes as soon that a required missing Resource is called.
I can prove with aapt list or unzipping the apk that strings.xml is missing.
Looking deep in the titanium javascript build file, I see this command is executed :
aapt "package" "-f" "-m" "-J" "/Users/nicorama/ti-voip/build/android/gen"
"-M" "/Users/nicorama/ti-voip/project/build/android/AndroidManifest.xml"
"-S" "/project/build/android/res"
"-S" "/var/folders/6f/twxz46614h7_q/res"
"-S" "/var/folders/6f/twxz46614h7_q/res" ....
The /var/folders/... are files for Titanium widgets. Compilation of the apk fails if I remove them.
I have executed this command outside the build, adding -v for verbose mode and saving result into a log.txt. I'm searching in this file for strings.xml and I find :
Found 18 custom asset files in /Users/nicorama/ti-voip/build/android/bin/assets
Configurations:
(default)
v11
v14
....
Src: () /var/folders/6f/twxz46614h7_q/res/values/ids.xml
values/strings.xml
Src: () /var/folders/6f/twxz46614h7_q/res/values/strings.xml
Src: (af) /var/folders/6f/twxz46614h7_q/res/values-af/strings.xml
Src: (am) /var/folders/6f/twxz46614h7_q/res/values-am/strings.xml
...
But nothing about my /Users/nicorama/ti-voip/build/android/res/values/strings.xml folder which is first in the appt command.
I do have all references needed for images or other xml files thought :
(new resource id hidden from /Users/nicorama/ti-voip/build/android/res/layout/hidden.xml)
(new resource id launcher from /Users/nicorama/ti-voip/build/android/res/layout/launcher.xml)
Any idea where and why this strings.xml has disappeared ?
aapt will merge all strings.xml "values" into resources.arsc, which is why you do not see the file strings.xml in the apk. I double checked this with few of my apks, i do not see the strings.xml inside the apk.
If you would like to see the string values that were packaged with your 'apk', run the below command it will dump all string values.
aapt.exe d strings myapp.apk
Verify some of the string values you defined in your app, are listed in the above string dump. If not, try passing in absolute path to the "res" folder "/Users/nicorama/ti-voip/project/build/android/res" at the beginning:
aapt "package" "-f" "-m" "-J" "/Users/nicorama/ti-voip/build/android/gen"
"-M" "/Users/nicorama/ti-voip/project/build/android/AndroidManifest.xml"
"-S" "/Users/nicorama/ti-voip/project/build/android/res"
"-S" "/var/folders/6f/twxz46614h7_q/res"
"-S" "/var/folders/6f/twxz46614h7_q/res" ....
the new apk should have the xml values, test again with
aapt.exe d strings myapp.apk
to make sure your strings.xml values are in the above string dump.

Categories

Resources