AAPT2 error - appcompat-v7 files not found in mergeDebugResources - android

I have a Hudson build job that's failing with the error
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
and in the logs, lots of lines like this:
C:\Windows\System32\config\systemprofile\.gradle\caches\transforms-1\files-1.1\appcompat-v7-26.1.0.aar\3bbc697d357b69b5ea5f78a35f99a514\res\color\abc_hint_foreground_material_dark.xml: error: file not found.
I've found a few questions on AAPT2 errors like this, for example this and this but they don't seem to have a fix.
So why is the build failing?

As per the first linked question, disabling AAPT2 seems like a bad idea, as AAPT might be removed at some point in the future.
The second linked question at least gives a clue, with the accepted answer there being that that version of gradle doesn't handle non-ASCII characters in the .gradle cache path. But in our case, there aren't any non-ASCII characters in the cache path being logged.
In fact, from the logs, gradle is looking for the cache inside C:\Windows\System32\config\systemprofile\.gradle, which is only accessible with admin privileges. Not somewhere we want to be caching libraries.
This answer, along with this post on the gradle forums are what led me to the solution. Short version is, by default gradle caches downloaded libraries in the user area, and there seems to be a bug in Java where it will incorrectly determine the users home directory. This results in the gradle cache being put somewhere it really shouldn't be.
To fix the problem, then, we just need to set gradle's user home directory. This blog post has a bunch of ways to do that. One way is to create a GRADLE_USER_HOME environment variable, which has the advantage of applying to all gradle builds on the machine.

Related

How can I fix "Type org.freedesktop.gstreamer.GStreamer is defined multiple times" error when building an Android APK?

I have been working on a project for a couple of months integrating gstreamer to a basic react-native Android app. The starting point was react-native-gstreamer but with a number of modifications to the gstreamer pipeline etc.
My debug builds (created with yarn android or ./gradlew assembleDebug) have been working reliably, on emulated and real devices, but I can't get a release build / signed APK ./gradlew assembleRelease to work. The build scan showing the error (created with ./gradlew assembleRelease --scan, doesn't appear to contain any sensitive information?) is at scans.gradle.com. The error I am stuck on is
C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex: D8: Type org.freedesktop.gstreamer.GStreamer is defined multiple times: C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex, C:\Temp\MyApp\react-native-gstreamer.transforms\b22258b54d8d354026f3fb18b0251db4\transformed\classes\classes.dex
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
I'm new to Android development (experienced C++/Python mainly), so I could be missing something obvious, this seems to be a common issue (see below) but the link in the error doesn't help me and the solutions I have found have not worked.
The most likely cause that I can't pin down is some sort of dependency clash, similar to this issue also, but I don't have lots of dependencies, it seems specifically related to gstreamer, and I don't know where to dig further to find the clash.
./gradlew app:dependencies doesn't show any obviously bad dependencies. react-native-gstreamer has a dependency on com.facebook.react:react-native:+ -> 0.63.4 (*) and doesn't appear in any other context in the dependencies (i.e. the above dependency appears a few times in the output, but react-native-gstreamer isn't a dependency of other packages and doesn't have other dependencies and there are no other occurrences of gstreamer)
Similar errors elsewhere on stackoverflow and solutions which I have unsuccessfully tested:
Delete gradle folder - fault still occurs
Enable multiDex in build.gradle - fault still occurs (note minSdkVersion is set to 21, so some messages suggest this should not be necessary, but tried anyway)
Similar to this but I am not aware of any dependency
./gradlew clean and ./gradlew assembleRelease - fault still occurs
Various solutions
look at the path given in AS, it should point to \app\build\intermediates\project_dex_archive\debug\out. Go to this path, delete all the *.jar files, leaving the most recent one - fault still occurs (removed file is recreated on next build)
Delete the build directory (C:/Temp/MyApp above) - fault still occurs
Multidex changes - it looks like this is now outdated for minSdkVersion >= 21, no upvotes and one comment that it didn't fix the original poster's problem, not tested.
The error message mentions two dex sources which contain the org.freedesktop.gstreamer.GStreamer class:
C:\Temp\MyApp\app\intermediates\project_dex_archive\release\out\org\freedesktop\gstreamer\GStreamer.dex
C:\Temp\MyApp\react-native-gstreamer.transforms\b22258b54d8d354026f3fb18b0251db4\transformed\classes\classes.dex
First source's project_dex_archive folder generally contains output artifacts which were built from project source files. Is it possible that your app module contains GStreamer.java source file?
If yes - then it might be the root cause of the conflict, since you're most likely have similar artifact packaged in a third party dependency (the second dex source: react-native-gstreamer).

Aapt2 exception even after disabling it

I have an old android project that is having compilation problems. I've added a gradle.properties file to root with a single line:
android.enableAapt2 = false
However, I'm still getting this error:
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT error: check logs for details
Which doesn't make sense to me because I've disabled aapt2 and it still seems to be using it. In addition, I've checked every log I can find with no additional information found on what is actually breaking.
As for your first question, the build is giving you an AAPT error, which might be coming from AAPT(1), not just AAPT2, that's why disabling AAPT2 doesn't "fix" it.
Secondly, disabling AAPT2 is not a solution. AAPT2 is telling you there's something wrong with your files. It fails the build early so that your app doesn't crash at run-time (which AAPT would silently allow).
Lastly, it's possible that you modified something in between the builds or that it didn't build in the past either. A way to figure out what the problem is, is to check the logs. If you're having trouble finding them in Android Studio (they will be in different places for different versions of Android Studio, Android Gradle Plugin and Gradle), an easy way to generate it is to go to the Terminal window in Android Studio and run "gradlew clean assembleDebug". The errors from AAPT/AAPT2 should be just above the stacktrace.

Android Studio AAPT1/AAPT2 errors

I have two separate errors relating to AAPT:
The first:
AAPT2 error : check logs for details
The second:
Failed to execute aapt
The first error can be solved by adding android.enableAapt2=false into the gradle.properties file, but this causes the second error to occur.
It appears as if though solving the first means the second never can be solved.
What can I do to get around this?
It seems to me that you are just avoiding the first error by disabling it. That will obviously cause problems if you need aapt (or more specifically, aapt2) to run.
As per my understanding, aapt1 will be removed at some point, so it is probably a bad idea to disable aapt2 anyway, as that will be the default in the future.
Instead, try to follow the advice given, and look for the real error in the Aapt log. Most likely there will be something wrong with one of your resource files.
PS: If you run your command with --stacktrace, it might output more useful information.

Android studio How to resolve Error in png files of library added

I have no Idea what is happening, last time when I finished my app I build its release apk and all was working just fine as expected but now today when I tried to make that pproject again and to make another apk I am getting the following error.
Error:Execution failed for task ':app:mergeDebugResources'.
Crunching Cruncher common_signin_btn_icon_pressed_light.9.png failed, see logs
I have no idea how to resolve it I have serached and found restarting Android studio and clean the project would remove it , doing this many times has no effect on this error. I have even restarted my machine but the condition of error in same.
In the logs I have seen that this png file is from the library I added , so just for testing I removed that library and tried to build then it started to give me same error with different png file name in other library. So how to fix this issue ?
My Questions are :
How can this issue be Solved ?
Have some one faced this problem too ?
Is this problem has been reported to google ?
Why in android we do not have any stable platform for development as IOS have ?
Try to remove "builds" folders and do rebuild. But soon, the whole thing in a long file name. Read this answer. By the way, you looked logs? Maybe this is not the PNG? You have not sent the log and did not specify the version Gradle.
Believe me, iOS developers have own problems.

I have error while compiling project in Qt

I have project created in Qt4.x and now I'm compiling this project on Qt5.3.1.
The project compiles well for Windows but when compiling for Android I get following error
:-1: error: No rule to make target '........\Softwares\Android-SDK-NDK-ANT\android-ndk-r9d-windows-x86_64\android-ndk-r9d\sources\cxx-stl\gnu-libstdc++\4.8\include\profile\impl\profiler_map_to_unordered_map.h', needed by 'ui_main_window.h'. Stop
Please help,
Thanks in advance
That's most probably related to this bug which is also discussed in this blog post. You are on Windows (first hint) and your NDK path seems quite long (second hint). These facts, combined with the long paths Qt Creator tends to create, generates paths that long to hit OS limits and then strange and cryptic errors can pop out of no where.
Quoting directly the linked post:
Try installing the NDK directly in the root with a short directory name, and have a shallow directory structure for the project you are building. If you still have problems, try turning off shadow building, as this appends a long directory name to your path.
Personally I've:
C:\AdtBundle\sdk
C:\AdtBundle\ndk9d
C:\Ant (a lot of deploy errors occur for a bad decision about Ant directory path...)
After setting such simple directory structure I've never encountered any strange error due to excessively long/bad paths.

Categories

Resources