com.android.builder.internal.aapt.v2.Aapt2InternalException - java

Problem
It is working fine when i am building without release option. release option was working fine with android version 7.1.4
What is expected to happen?
it should build successfully
What does actually happen?
cordova build android --release
Information
build gradle file:
https://gist.github.com/indraraj26/a6efaed1135b0e394a23a1b192bc2c0c
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.3.0-5013011-windows Daemon #0: Unexpected error during compile 'D:\client\platforms\android\app\src\main\res\drawable-land-xxxhdpi\screen.png', attempting to stop daemon. FAILED
20 actionable tasks: 1 executed, 19 up-to-date
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
D:\client>if "1" == "0" goto mainEnd
D:\client>rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
D:\client>rem the _cmd.exe /c_ return code!
D:\client>if not "" == "" exit 1
D:\client>exit /b 1
Command finished with error code 1: D:\client\platforms\android\gradlew cdvBuildRelease,-b,D:\client\platforms\android\build.gradle
D:\client\platforms\android\gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.3.0-5013011-windows Daemon #0: Unexpected error during compile 'D:\client\platforms\android\app\src\main\res\drawable-land-xxxhdpi\screen.png', attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Picked up _JAVA_OPTIONS: -Xmx512M
Error: D:\client\platforms\android\gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.3.0-5013011-windows Daemon #0: Unexpected error during compile 'D:\client\platforms\android\app\src\main\res\drawable-land-xxxhdpi\screen.png', attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Picked up _JAVA_OPTIONS: -Xmx512M
at ChildProcess.whenDone (D:\client\node_modules\cordova-common\src\superspawn.js:135:23)
at ChildProcess.emit (events.js:198:13)
at ChildProcess.cp.emit (D:\client\node_modules\cordova-common\node_modules\cross-spawn\lib\enoent.js:34:29)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd build android --release --verbose exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
Command or Code
Environment, Platform, Device
Version information
ionic info
[WARN] Detected locally installed Ionic CLI, but it's too old--using global CLI.
Ionic:
Ionic CLI : 5.4.4 (C:\Users\HP\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
#ionic/app-scripts : 3.2.2
Cordova:
Cordova CLI : 8.1.2 (cordova-lib#8.1.1)
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-webview 1.2.1, (and 15 other plugins)
Utility:
cordova-res : 0.8.1
native-run : 0.2.9
System:
Android SDK Tools : 26.1.1 (C:\Users\HP\AppData\Local\Android\Sdk)
NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.10.2
OS : Windows 10
with this solution : https://stackoverflow.com/a/50973967/10842900
i am able to build apk but getting this errors
D:\client\platforms\android\app\src\main\res\drawable-land-hdpi\screen.png: Error: The drawable "screen" in drawable-land-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-land-ldpi\screen.png: Error: The drawable "screen" in drawable-land-ldpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-land-mdpi\screen.png: Error: The drawable "screen" in drawable-land-mdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-land-xhdpi\screen.png: Error: The drawable "screen" in drawable-land-xhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-land-xxhdpi\screen.png: Error: The drawable "screen" in drawable-land-xxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-land-xxxhdpi\screen.png: Error: The drawable "screen" in drawable-land-xxxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-port-hdpi\screen.png: Error: The drawable "screen" in drawable-port-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-port-ldpi\screen.png: Error: The drawable "screen" in drawable-port-ldpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-port-mdpi\screen.png: Error: The drawable "screen" in drawable-port-mdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-port-xhdpi\screen.png: Error: The drawable "screen" in drawable-port-xhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-port-xxhdpi\screen.png: Error: The drawable "screen" in drawable-port-xxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
D:\client\platforms\android\app\src\main\res\drawable-port-xxxhdpi\screen.png: Error: The drawable "screen" in drawable-port-xxxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
Explanation for issues of type "MissingDefaultResource":
If a resource is only defined in folders with qualifiers like -land or -en,
and there is no default declaration in the base folder (layout or values
etc), then the app will crash if that resource is accessed on a device
where the device is in a configuration missing the given qualifier.
As a special case, drawables do not have to be specified in the base
folder; if there is a match in a density folder (such as drawable-mdpi)
that image will be used and scaled. Note however that if you only specify
a drawable in a folder like drawable-en-hdpi, the app will crash in
non-English locales.
There may be scenarios where you have a resource, such as a -fr drawable,
which is only referenced from some other resource with the same qualifiers
(such as a -fr style), which itself has safe fallbacks. However, this still
makes it possible for somebody to accidentally reference the drawable and
crash, so it is safer to create a default dummy fallback in the base
folder. Alternatively, you can suppress the issue by adding
tools:ignore="MissingDefaultResource" on the element.
(This scenario frequently happens with string translations, where you might
delete code and the corresponding resources, but forget to delete a
translation. There is a dedicated issue id for that scenario, with the id
ExtraTranslation.)
12 errors, 0 warnings

The reason this is failing is that there was a bug in aapt2's code for crunching (compressing) PNG files. PNG crunching is automatically disabled for debug builds, but turned on for release, that's why you only saw this in your release builds.
This has been fixed now, so just update your android gradle plugin version and you will get the aapt2 with the fix automatically. I'd suggest 3.5 or newer.
I also see you're on windows, so you might run into another issue that's common if you try to update to 3.5. Aapt2 daemons might fail to start - in that case you just need to install the Windows Universal C Runtime Library.

Related

Can't Clean project with Failed to create parent directory '/.gradle' when creating directory

I upgraded my project from:
compileSdkVersion 30
To:
compileSdkVersion 32
and every time i Clean the project i keep getting the error
Failed to create parent directory '/.gradle' when creating directory
the full error is:
Gradle could not start your build.
> Cannot create service of type DefaultConfigurationCache using DefaultConfigurationCache constructor as there is a problem with parameter #10 of type ConfigurationCacheFingerprintController.
> Cannot create service of type ConfigurationCacheFingerprintController using ConfigurationCacheFingerprintController constructor as there is a problem with parameter #5 of type FileCollectionFingerprinterRegistry.
> Cannot create service of type FileCollectionFingerprinterRegistry using method VirtualFileSystemServices$BuildSessionServices.createFileCollectionFingerprinterRegistry() as there is a problem with parameter #1 of type List<FileCollectionFingerprinter>.
> Could not create service of type CrossBuildFileHashCache using BuildSessionServices.createCrossBuildFileHashCache().
> Failed to create parent directory '/.gradle' when creating directory '/.gradle/6.8/fileHashes'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I tried cleaning the Cash folder in the .gradle folder or renaming the /.gradle/deamon/6.8 folder
but both didn't work
any ideas why it's happening ? or how i can fix it on a mac ?

./gradlew assemble fails due to missing file when the file clearly exists

I'm trying to build JPostal as described in this link using the following command:
./gradlew assemble
However, the command produces the following output claiming the file C:\x\Program Files\Msys64\usr\share does not exist when it clearly does:
$ ./gradlew assemble
:buildJniLibaclocal-1.16: error: aclocal: file '/x/Program Files/Msys64/usr/share/aclocal/tcl-tea.m4' does not exist
autoreconf-2.71: error: aclocal failed with exit status: 1
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: Files/JPostal/src/main/jniLibs
configure: error: cannot find required auxiliary files: compile config.guess config.sub ltmain.sh missing install-sh
make: *** No rule to make target 'install'. Stop.
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildJniLib'.
> Process 'command 'sh'' finished with non-zero exit value 2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.844 secs
I can clearly see a file named tcl-tea.m4 in the directory: C:\x\Program Files\Msys64\usr\share\aclocal
See the screenshot below:
If the file clearly exists, why am I getting this error? Why is the file being discriminated against?
Despite these are supported, but paths with spaces generally tend to be problematic on Linux.
Even without the build.gradle, the path is obviously wrong; this likely needs to be escaped:
"C:\\x\\Program\ Files\\Msys64\\usr\\share\\aclocal"
Where \\ gives \ and \ gives .
To use ${File.separator} would be the alternate cross-platform approach.
This would give \ on Windows and / on Linux.

how to fix fastlane error: Keystore file 'keystore.jks' not found for signing config 'externalOverride'.?

Am new to fastlane, when I write the command for deploy the app to internal test its show me the following error:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:validateSigningRelease'.
Keystore file '/Users/rooh/.gradle/daemon/5.1.1/keystore.jks' not found for signing config 'externalOverride'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
It seems that the error because the location of the keystore, I already put the keystore in app file of the project, I did that in other project and its work fine, but in this I dont know why its not working
I also tried to change the keystore location but still
this lane in fastfile:
desc "Deploy a new internal version to the Google Play Store"
lane :internal do
gradle(task: "clean")
gradle(
task: "assemble",
build_type: "Release",
print_command: false,
properties: {
"android.injected.signing.store.file" => "keystore.jks",
"android.injected.signing.store.password" => "*****",
"android.injected.signing.key.alias" => "alias",
"android.injected.signing.key.password" => "*****"
}
)
changelog = prompt(
text: "Changelog: ",
multi_line_end_keyword: "END"
)
supply(
track: "internal",
apk: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH].to_s
)
upload_to_play_store(track: "internal")
end
As #Rooh Al-mahaba says, I had to supply the complete filepath as the value for "android.injected.signing.store.file".
Also, ~/ didn't work; I needed to explicitly spell out the full filepath.
INFO: For other users:
You can create several ENV variables, this is useful for CI.
build_android_app(
task: "assemble",
build_type: "Release",
flavor: "development",
flags: "--stacktrace",
print_command: false,
properties:{
"android.injected.signing.store.file" => ENV['KEYSTORE_PATH'],
"android.injected.signing.store.password" => ENV['STORE_PASSWORD'],
"android.injected.signing.key.alias" => ENV['KEY_ALIAS'],
"android.injected.signing.key.password" => ENV['KEY_PASSWORD'],
"org.gradle.java.home" => ENV['JAVA_HOME']
})
Later you need to modify .bash_profile and add the ENV variables.
Flutter + Fastlane + GitHub Actions
I had the same issue and, in my case, I was able to make it work by placing the keystore file in both ./android/fastlane/ and ./android/app/fastlane/ folders.
That is because I had my Fastlane configuration inside the ./android/fastlane/ folder, however, when you run build_android_app / gradle task it will try to fetch the keystore file in the ./android/app/ folder by default, and you cannot tell it to do otherwise unless you use an absolute path (not a good practice) since Fastlane tasks can't parse relative paths. Moreover, if I were to remove the keystore file from the ./android/fastlane/ folder, it would complain, even if it was present in ./android/app/fastlane/.

React Native Splash Screen Issue - after modifying xml files in android folder

I would like to create a splash screen in my React Native app (not Expo) using Android Studio's emulator.
I was trying to add a splash_screen.xml file into android/app/src/main/res/drawable folder. When I put a new .xml file into the android folder the React compiler shows the following error message:
iMac:newtest Dora$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Configure project :app
WARNING: The specified Android SDK Build Tools version (28.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '28.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Task :app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugResources'.
com.android.build.gradle.tasks.ResourceException (no error message)
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 2s
9 actionable tasks: 1 executed, 8 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
Command failed: ./gradlew installDebug
Error: Command failed: ./gradlew installDebug
at checkExecSyncError (child_process.js:637:11)
at Object.execFileSync (child_process.js:655:13)
at runOnAllDevices (/Users/Dora/Documents/code/react native/newtest/node_modules/react-native/local-cli/runAndroid/runAndroid.js:299:19)
at buildAndRun (/Users/Dora/Documents/code/react native/newtest/node_modules/react-native/local-cli/runAndroid/runAndroid.js:135:12)
at isPackagerRunning.then.result (/Users/Dora/Documents/code/react native/newtest/node_modules/react-native/local-cli/runAndroid/runAndroid.js:65:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
Thank you for taking your time to help me to solve this issue!
Cheers,
Alex
Well, finally I have managed to solve this issue. It is for those who will encounter this problem during Android development.
So, what i did exactly:
1. cd into android folder and run this: ./gradlew installDebug
After this command finished without any errors
go back to the root directory and start the app using: react-native run-android
Conclusion, if you add or change any xml files in android folder, you have to do the above procedure.
That's all!
Alex

Jenkins Android Build Error: FAILURE: Build failed with an exception

I have been trying to do CI using Jenkins for my Android application. I am new to this. After following some of the tutorials, I am able to atleast set up and run the build now option. It download every pom required but while building it give below error.
============================================
C:\Windows\System32\config\systemprofile.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\e796469c387c11565d873216f24c3b6f\res\drawable\abc_ic_go_search_api_material.xml: error: file not found.
C:\Windows\System32\config\systemprofile.gradle\caches\transforms-1\files-1.1\play-services-base-15.0.1.aar\7207fbd3bdb6cb696445cfc77c16e5ed\res\drawable-hdpi-v4\googleg_standard_color_18.png: error: file not found.
C:\Windows\System32\config\systemprofile.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\e796469c387c11565d873216f24c3b6f\res\layout\select_dialog_singlechoice_material.xml: error: file not found.
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugResources'.
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
======================================================
Can you please let me know how to resolve it?
Do let me know if anything else is required.
Maybe the path is too long. Try this:
Jenkins --> Project --> Project Configuration --> Build
Select advanced option
Check the option box "Force GRADLE_USER_HOME to use workspace"
Build your project
I solved my problem by this way, good luck!
Try updating your android gradle plugin version to 3.2.0-alpha12 or newer. AAPT2's version included in these versions contains many fixes for path support on Windows which resulted in similar errors.
you can solve this by separating into smaller group of task
make separate invoke gradle script under build tab
clean build assembleDebug
test
connectedAndroidTest
i had similar issues, when i ran assembleDebug and test together in Jenkins as a single task
When using Jenkins with Window to build Android, I face this problem myself.
I fix by add GRADLE_USER_HOME to Environment Variable:
GRADLE_USER_HOME = C:\Users\*MyUserName*\.gradle
hope this help,

Categories