A problem occurred configuring root project 'android' Flutter - android

I have this error can you tell me what's the solution for it?
Launching lib\main.dart on sdk gphone x86 in debug mode...
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'android'.
Could not resolve all artifacts for configuration ':classpath'.
Could not download builder.jar (com.android.tools.build:builder:3.5.0)
Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.5.0/builder-3.5.0.jar'.
Premature end of Content-Length delimited message body (expected: 8174407; received: 4456416
Could not download bundletool.jar (com.android.tools.build:bundletool:0.9.0)
Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.9.0/bundletool-0.9.0.jar'.
Premature end of Content-Length delimited message body (expected: 5248142; received: 4456416
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 21m 37s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

Whether the first time or not. When you click run on your application you get an X gradle build error If you have any of the following lines in your error even a single line then try this solution
Launching lib\main.dart on sdk gphone x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not download builder.jar (com.android.tools.build:builder:3.5.0)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.5.0/builder-3.5.0.jar'.
> Premature end of Content-Length delimited message body (expected: 8174407; received: 4456416
> Could not download bundletool.jar (com.android.tools.build:bundletool:0.9.0)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.9.0/bundletool-0.9.0.jar'.
> Premature end of Content-Length delimited message body (expected: 5248142; received: 4456416
SOLUTION
Go this location:- .flutter/packages/flutter_tools/gradle/flutter.gradle
**
Backup the file in another place before making edits to it
Search for something called buildscript;
It should come up like that (or similar, don't worry you have a backup file)
and overwrite this code
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
With this
buildscript {
repositories {
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
Still, your problem is not solved? If it was solved DON'T try the next one if not then try it. (And even if this didn't work then put the backup file in its place and see if it's working)
Then in your android folder go to build.gradle (in your project files go to
android/build.gradle) and change the buildscript to this (Don't worry about the code not being 100% like this. Just add the specified line in the shown location and that's it)
buildscript {
repositories {
google()
mavenCentral() //add this line
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' // Doesn't matter what you have here
}
}

Just make Flutter clean in android studio or VScode

If you already have mavenCentral() added inside buildscripts{...} and allprojects{...}
inside build.gradle file,
then add jcenter() after each mavenCentral().
or, vice-versa

If you got AndroidX incompatibilities in a plugin as well then just focus on following versions:
change your compileSdkVersion 30 in app\build.gradel
Try to change this accordingly
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
Try to change gradle version in gradle->wrapper->gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-6.6.1-all.zip

I solved the problem with <uses-permission android:name="android.permission.INTERNET" /> in androidManifest.xml

I solved the problem by deleting the .gradle folder in C:user/

Related

Could not HEAD 'https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

I am trying to build my react-native project for android and getting the following error on Windows but its working on Mac.
$ react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1090 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Installing the app...
> Task :react-native-get-sms-android:generateDebugRFile FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
128 actionable tasks: 128 executed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-get-sms-android:generateDebugRFile'.
> Could not resolve all files for configuration ':react-native-get-sms-android:debugCompileClasspath'.
> Could not resolve com.facebook.react:react-native:+.
Required by:
project :react-native-get-sms-android
> Failed to list versions for com.facebook.react:react-native.
> Unable to load Maven meta-data from https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml.
> Could not HEAD 'https://jcenter.bintray.com/com/facebook/react/react-native/maven-metadata.xml'. Received status code 502 from server: Bad Gateway
* 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 24s
My Environment:
Windows 10 Home
React Native v66.4
NodeJS v12.18.1
Found solutions when googled about this error that bintray was down and its status could be tracked at https://status.bintray.com.
But building the project works fine on Mac environment, and at the same time, it is failing in Windows with Received status code 502 from server: Bad Gateway. Any clues on this weird behavior?
If Osvaldo's solution doesn't work, another one is to update your dependency itself which relies on jcenter in its gradle at the current version.
In this case, it's react-native-get-sms-android. Updating it may free it from jcenter.
In my case, it was an old version of react-native-sqlite-2.
I had the same issue nad removing jcenter and adding maven solved my problem:
The android/build.gradle file:
repositories {
+ mavenCentral()
google()
- jcenter()
gradlePluginPortal()
}
~ ~ ~
dependencies {
~ ~ ~
+ mavenCentral()
google()
- jcenter()
+ gradlePluginPortal()
maven { URL 'https://www.jitpack.io' }
}
Hint: The + sign means add this line and the - means remove that line.
Hot news
Yesterday morning jcener was shutdown by Facebook, so in one of my cases because issue was inside a package in node_modules folder, I used the following solution instead of above to permanently remove whatever related to jcenter:
The android/build.gradle file of that package in node_modules folder:
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
remove repo
}
}
}
To keep this node_modules changes in the production environment use patch-package.

Could not find com.android.support:appcompat-v7:23.1.1

I checked out and built the project at https://github.com/kosiara/artoolkit-android-studio-example
I have Android Studio 4.0.2 on Windows 10.
The build error I get is:
Executing tasks: [:app:assembleDebug] in project D:\Downloads\artoolkit-android-studio-example-master\artoolkit-android-studio-example-master
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> A problem occurred configuring project ':base'.
> Could not resolve all dependencies for configuration ':base:_debugCompile'.
> Could not find com.android.support:appcompat-v7:23.1.1.
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.1.1/appcompat-v7-23.1.1.pom
https://jcenter.bintray.com/com/android/support/appcompat-v7/23.1.1/appcompat-v7-23.1.1.jar
Required by:
artoolkit-android-studio-example-master:base:unspecified
* 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: 1.346 secs
I'm afraid I don't understand what is wrong.
I'm not sure what needs to be set to version 23.1.1. I looked in my Android SDK manager under SDK Tools, Android SDK Build-Tools and there is no option for 23.1.1. (Is that even where I should be looking?) I see 23.0.1, 23.0.2 (Installed), 23.0.3. Also the Android SDK Platform 23 is installed.
Do I need to add a custom Site to get the missing 23.1.1 option? I have no idea how to do that or what site it would be, if that's what's required.
I suspect there's likely something not set up correctly about my SDK or Android Studio, but I don't know what to check next.
I see this related question but that question has no answer.
I'd like some help getting this example to build.
That version of that module (appcompat-v7) is not in the JCenter repository.
You have to add google maven using the old way when you're using an old version of Gradle, you are not allowed to use google() on Gradle v1.5.
build.gradle (project level)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Android studio compilation error from kotlin

I tried compiling android but it gives me the following error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Could not resolve all files for configuration ':app:_internal_aapt2_binary'.
> Could not resolve com.android.tools.build:aapt2:3.6.3-6040484.
Required by:
project :app
> No cached version of com.android.tools.build:aapt2:3.6.3-6040484 available for offline mode.
> No cached version of com.android.tools.build:aapt2:3.6.3-6040484 available for offline mode.
* 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
I saw this web page https://discuss.gradle.org/t/cached-version-error/35754
It says I should increase kotlin version but when I went into the build.gradle of my app, I did not see any kotlin in it. This is the build.gradle of my app
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I don't think your issue is related to kotlin version. Looks like either you don't have a proper internet connection and your project its failing to download build tools 3.6.3 or you have "offline mode" enabled for gradle plugin.
If you are sure you have a proper internet connection, check if you have offline mode enabled in
Android Studio File -> Settings -> Build, Execution, Deployment -> Gradle
Or the quickest by just typing offline mode in the Android studio actions.
Hit shift + cmnd + a in Mac or shift + cntrl + a in windows.
Then type "offline mode"
Disable it
Sync gradle and run your proyect again.
This should solve the issue.

Build Android APK in Redhat using Gradle in Offline mode

I am using Gradle 2.13 and trying to build android apk in readhat and system does not have internet access.
I am trying to build android apk offline. But it is throwing some exception and not able to figure out what went wrong.
Main build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'PROJECT'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:2.1.0.
Required by:
:PROJECT:unspecified
> No cached version of com.android.tools.build:gradle:2.1.0 available for offline mode.
> No cached version of com.android.tools.build:gradle:2.1.0 available for offline mode.
* 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: 0.831 secs
Version :
gradle -version
Gradle 2.13
Is there any tutorial available to build an offline apk in redhat/linux machine?
Edit: Update the question.
It happens because the gradle plugin for android 2.13 doesn't exist.
The latest stable version is 2.1.0. Use:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
Don't confuse gradle distribution and the android plugin for gradle.
You can define the gradle distribution used by a project in the file
gradle/wrapper/gradle-wrapper.properties
For example:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

Cannot build an Android app with Gradle, except with sudo

I am trying to run a simple 'hello world' android app with gradle build. It builds fine if I issue the command
sudo ./gradlew build --> builds fine
But without sudo,
./gradlew build --> shows following error
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':MyStudioApplication'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':MyStudioApplication:_DebugCompile'.
> Could not find any version that matches com.android.support:appcompat-v7:+.
Required by:
workspace:MyStudioApplication:unspecified
* 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: 12.621 secs
following is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Please help
Taking a shot in the dark here, you may have run your initial gradle build with sudo which may have caused the artifacts to be downloaded and permisionned to root and are not accessible to your regular user. To test this assumption you may want to rename your local repository where gradle downloads the dependencies and rerun gradle as the standard user.
if you get the similar "cannot resolve symbol" appcompatactivity but running as sudo resolves things, try deleting the .AndroidStudio folder in your /home directory
This started happening to me after cleaning/building with sudo.
What worked for me was:
sudo ./gradlew clean
File -> Invalidate caches (check clear file system..., and restart)
delete manually one of the build folders, it was a multi-module project, and for some reason that module wasn't been deleted

Categories

Resources