Build Failed, Missing 'package' key attribute - java

I'm trying to generate signed apk and I keep getting this error. I searched on Google for the error but haven't come up with anything solid. Any help would be great. Thank you.
Task :app:processReleaseManifest FAILED [com.facebook.android:audience-network-sdk:6.4.0] /Users/xxxx/.gradle/caches/transforms-2/files-2.1/1208b0b00589b6f8b9220695fa10ec7b/audience-network-sdk-6.4.0/AndroidManifest.xml:12:9-55 Error: Missing 'package' key attribute on element package at [com.facebook.android:audience-network-sdk:6.4.0] AndroidManifest.xml:12:9-55 [com.facebook.android:audience-network-sdk:6.4.0] /Users/xxxx/.gradle/caches/transforms-2/files-2.1/1208b0b00589b6f8b9220695fa10ec7b/audience-network-sdk-6.4.0/AndroidManifest.xml Error: Validation failed, exiting
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed with multiple errors, see logs

It's probably because some changes the Android team has made on Gradle. Right now, if your Gradle version is lower than 4.1, you'll probably see one or a combination of these errors:
Android resource linking failed /Users/sample/AndroidStudioProjects/MyApp/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml:18: error: unexpected element <queries> found in <manifest>
Manifest merger failed with multiple errors, see logs
Error: Missing 'package' key attribute on element package
To solve them, they suggest doing one of two things:
1. Upgrade your Gradle to 4.1 version or higher
Just update your build.gradle file by changing the version in the classpath.
buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android Gradle plugin 3.0.0 or higher.
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0' //change it here
}
}
2. Update your Gradle to a version compatible with your current version
If you don't want to update your Gradle to the latest version, you can stick with your current by changing it to a dot release equivalent to the version you are using without having to worry with compatibility issues.
Your current version
Dot release equivalent
4.1.*
No upgraded needed
4.0.*
4.0.1
3.6.*
3.6.4
3.5.*
3.5.4
3.4.*
3.4.3
3.3.*
3.3.3
So for instance, if you're running your app at 4.0.0 you just change it to 4.0.1 also in the build.gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}
Google suggests using the second option if your app is depending on third party APIs or old Gradle versions.
We know that not everyone is ready to upgrade to the latest version, though, and you may be relying on old versions of Gradle or libraries that aren’t compatible with 4.1.
You can learn more about what's changed in their official post here.

Related

maven does not have spring version 3 or version 4?

I was trying to run a legacy project using spring version 3 with build.gradle:
...
plugins {
id 'java'
id 'maven-publish'
id 'war'
}
repositories {
mavenLocal()
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
}
ext {
org_springframework_version = '3.2.18.RELEASE'
}
dependencies {
...
implementation 'org.springframework.ldap:spring-ldap-core:2.4.1'
implementation "org.springframework:spring-web:${org_springframework_version}"
implementation "org.springframework:spring-webmvc:${org_springframework_version}"
implementation "org.springframework:spring:${org_springframework_version}"
...
}
...
but getting the following error when trying to build:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.springframework:spring:3.2.18.RELEASE.
Searched in the following locations:
- file:/C:/Users/.../.m2/repository/org/springframework/spring/3.2.18.RELEASE/spring-3.2.18.RELEASE.pom
- https://repo.maven.apache.org/maven2/org/springframework/spring/3.2.18.RELEASE/spring-3.2.18.RELEASE.pom
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I checked https://repo.maven.apache.org/maven2/org/springframework/spring/ and it looks like there is no spring 3 or 4 in the repo.
I cannot use any newer spring version as there are tons of other dependencies and legacy code in the project that should be kept as is.
I am confused as to why is this the case or how to build my project now.
Any help is appreciated.
PS. A little background: I have a legacy project that relies on really old tech (Stripes framework) which is straight up refusing to work with spring 5+. It is running on Java 6 now. I want to upgrade it to java 8. But spring 2.x dependency is not letting me to.
The fullblown spring.jar hasn't been available since Spring Framework 3.0.0. Spring 2.5.6 is the last one that has the full Spring jar. Since then only the smaller modules have been available.
The versions for 5.x you see are only some top level pom.xml files which, I assume, have been published accidentally (as for 6.x they aren't there anymore).
In short remove the following line from your dependencies
implementation "org.springframework:spring:${org_springframework_version}"
So it doesn't try to resolve something that hasn't been available since Spring 2.5.6 anymore. What you should include are the dependencies for the modules you need (something like the below dependencies).
implementation "org.springframework:spring-web:${org_springframework_version}"
implementation "org.springframework:spring-webmvc:${org_springframework_version}"
implementation "org.springframework:spring-jdbc:${org_springframework_version}"
implementation "org.springframework:spring-orm:${org_springframework_version}"
implementation "org.springframework:spring-oxm:${org_springframework_version}"
As an additional note replace
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
with
mavenCentral()
This will allow Gradle to pick a better suited mirror of Maven for your environment.

Android Studio 4.2 doesn’t recognize any syntax in KotlinScript Gradle build.gradle.kts, even though 4.1.3 works fine with Gradle 7.0

Versions
Android Studio 4.2
Gradle 7.0
AGP: 4.1.3 (I see the same results with AGP 4.2, so I am opting instead to keep as many variables constant as possible.)
Kotlin: 1.5
JDK: /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/java -version is
openjdk version "11.0.8" 2020-07-14
Mac OX Big Sur 11.3.1
After upgrading to Android Studio 4.2, my project cannot be built. All my KotlinScript files fail to be recognized by AS, and Gradle sync fails as well.
Gradle on the command-line continues to work correctly.
This is my top-level build.gradle.kts, and I see the same results for every module as well (this one is just one of several samples). Image with syntax highlighting issues is here: https://i.stack.imgur.com/bvjVz.png
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
extra["kotlin_version"] = "1.5.0"
repositories {
google()
}
dependencies {
classpath(kotlin("gradle-plugin", version = rootProject.extra["kotlin_version"] as String?))
classpath("com.android.tools.build:gradle:4.1.3")
classpath("com.squareup.sqldelight:gradle-plugin:1.4.4")
classpath("com.github.ben-manes:gradle-versions-plugin:0.38.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id("com.github.ben-manes.versions") version "0.38.0"
id("io.gitlab.arturbosch.detekt") version "1.16.0"
}
allprojects {
repositories {
google()
jcenter()
maven("https://jitpack.io")
}
}
subprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
}
detekt {
config = rootProject.files("detekt.yml")
reports {
html {
enabled = true
destination = file("build/reports/detekt.html")
}
}
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
Summary of errors:
Cannot access 'java.lang.Object' which is a supertype of 'org.gradle.kotlin.dsl.KotlinBuildScript'. Check your module classpath for missing or conflicting dependencies
Cannot access 'java.lang.Comparable' which is a supertype of 'org.gradle.kotlin.dsl.KotlinBuildScript'. Check your module classpath for missing or conflicting dependencies
I tried making my project compatible with the latest versions of everything, including Gradle 7.0. The only variable that breaks the project is upgrading Android Studio to 4.2, with no changes to the source tree.
Is this a known issue / am I missing something obvious?
I am used to my project breaking every time the Android Gradle Plugin is updated, but this time, it’s happening even without any changes to source.
I had the exact same issue this morning after I updated the Android Studio from 4.2.0 to 4.2.1 version on my Linux machine.
Here is how I fixed it:
Open a "Project Structure" dialog.
Choose "SDK Location" on the left side of the dialog window.
Change "JDK location" path from build in to another one installed on your system. Like: /usr/lib/jvm/java-11-openjdk. And apply changes.
Return build in "JDK location" path and apply changes.
Errors should be gone now.

Android Studio - Rebuild Project - Could not download aapt2-4.1.0-6503028-windows.jar

This is the configuration I have on my project:
Android Studio 4.1 (September 23, 2020)
Android Gradle Plugin Version 4.1.0
Gradle Version 6.7
Compile SDK 29 (Android 10.0 Q)
Build Tools 29.0.2
Min Sdk 17
Target Sdk 26 (Android 8.0 Oreo)
In the build.gradle of the project I have
buildscript {
repositories {
google()
jcenter()
}
}
....
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
When I use the "Build> Rebuild Project" command in Build Output I get this error:
Execution failed for task ':app:mergeDebugResources'.
Could not resolve all files for configuration ':app:_internal_aapt2_binary'.
Could not download aapt2-4.1.0-6503028-windows.jar (com.android.tools.build:aapt2:4.1.0-6503028): No cached version available for offline mode
Possible solution:
- Disable offline mode and rerun the build
I tried with the "Toggle Offline Mode" in the Gradle panel (both to set it and to remove it), but the error still occurs.
I tried to clean the whole .gradle folder but same result.
I also created an emulator with API 30 because they suggested it would download the missing package, but it didn't change the situation.
I tried to manually download the jar (https://maven.google.com/web/index.html?q=aapt2#com.android.tools.build:aapt2:4.1.0-6503028) and put it in libs, but the error still comes out.
A month too late for this, but I was also getting a similar error with not being able to download aapt2, but for a different version number.
Turns out, the order of the google() dependency mattered as mentioned here: https://developer.android.com/studio/releases/#aapt2_gmaven
So everywhere you are adding the dependency for google() move it up, and it should work for you as well.
copy this
implementation 'com.android.tools.build:aapt2:4.1.0-6503028'
in Gradle in the Android Studio after that click Sync Now after finished click run to try

Plugin was not found with building gradle

Having a gradle project.
When i'm trying to build project.
buildscript {
ext {
springBootVersion = '2.2.4.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "gradle.plugin.org.hidetake:gradle-swagger-generator-plugin:2.9.0"
classpath "net.ltgt.gradle:gradle-apt-plugin:0.21"
}
}
plugins {
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt-idea" version "0.15"
id "net.ltgt.apt" version "0.15"
}
I have error which is connected with plugins
Plugin [id: 'net.ltgt.apt-eclipse', version: '0.15'] was not found in any of the following sources:
How to fix it?
I was facing the same issue. In build.gradle, the paths provided for the dependencies weren't matching the folders specified. Placing the folders in the mentioned path shown in the build.gradle solved it. After that I was able to build the project without errors.
TL;DR: If you are using a current gradle version, it's fine to just drop all of the net.ltgt.apt dependencies. You will not need it anymore because, it's features are now available natively in Gradle.
More details:
From the plugin README.md (https://github.com/tbroyer/gradle-apt-plugin#readme)
The goal of this plugin was to eventually no longer be needed, being superseded by built-in features. This has become a reality with Gradle 5.2 and IntelliJ IDEA 2019.1. tl;dr: this plugin is obsolete, don't use it. If you're using Eclipse though, continue reading.
It originally did a few things to make it easier/safer to use Java annotation processors in a Gradle build. Those things are now available natively in Gradle, so what's this plugin about?
If you use older versions of Gradle (pre-4.6), you can still benefit from those features:
it ensures the presence of configurations for your compile-time only dependencies (annotations, generally) and annotation processors, consistently across all supported Gradle versions;
automatically configures the corresponding JavaCompile and GroovyCompile tasks to make use of these configurations, when the java or groovy plugin is applied.
With recent versions of Gradle (between 4.6 and 5.1), this plugin will actually only:
add some DSL to configure annotation processors; it is however recommended to directly configure the tasks' options.compilerArgs;
backport the sourceSet.output.generatedSourcesDirs Gradle 5.2 API;
configure JavaCompile and GroovyCompile tasks' options.annotationProcessorGeneratedSourcesDirectory with a sane default value so you can see the generated sources in your IDE and for debugging, and avoid shipping them in your JARs.

Gradle error for build tools for pom and jar files

I wanted to use android gradle 5.5.1 which requires plugin version 3.4.0+ and I'm using plugin version 3.4.2 but when i try to make project i got 4 errors finding .pom and .jar files related to android.tools.build.gradle:3.4.2
I'm freaking and i really need help
Thanks
these is the error
ERROR: Could not find com.android.tools.build:gradle:3.4.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.2/gradle-3.4.2.pom
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.2/gradle-3.4.2.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.2/gradle-3.4.2.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.2/gradle-3.4.2.jar
Required by:
project :
Open File
well i tried checking proxy in android studio and it was ok and actualy it download all gradle without any problem. i even used offline gradle but nothing changed ,and i don't know what to do anymore. in repositories i'm using google() ,so don't tell to use google()
here is my gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-5.5.1-all.zip *
and here's my build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
} *
I ended up going in the build.gradle file, and adding google() right above jcenter(), like so.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
}
}
Once I did that, it stopped complaining. I found my answer in the following related question https://stackoverflow.com/a/44071571/11865353
Problem just solved,Because I live in Iran google doesn't allow my ip address to download these files so the solution was to change my ip dns address to something that googlw allows me to download
Solved

Categories