-1

I've just installed android studio and vscode to start learning flutter. so when I try to run the Demo app on (chrome) the app works perfectly fine, but when trying to debug on my phone with usb-cable it fails. I can't use emulator because I have an old pc

tried flutter run -v and it gave me this:

    [  +25 ms] Building APK
[  +70 ms] Running Gradle task 'assembleDebug'...
[  +14 ms] Using gradle from C:\Users\hh\StudioProjects\untitled\android\gradlew.bat.
[  +48 ms] executing: C:\Program Files\Android\Android Studio\jre\bin\java -version
[ +206 ms] Exit code 0 from: C:\Program Files\Android\Android Studio\jre\bin\java -version
[        ] openjdk version "11.0.10" 2021-01-19
           OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
           OpenJDK 64-Bit Server VM (build 11.0.10+0-b96-7249189, mixed mode)
[   +3 ms] executing: [C:\Users\hh\StudioProjects\untitled\android/] C:\Users\hh\StudioProjects\untitled\android\gradlew.bat -Pverbose=true
-Ptarget-platform=android-arm64 -Ptarget=C:\Users\hh\StudioProjects\untitled\lib\main.dart -Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==
-Pdart-obfuscation=false -Ptrack-widget-creation=true -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root assembleDebug
[+12814 ms] Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
[+123489 ms] FAILURE: Build failed with an exception.
[  +27 ms] * What went wrong:
[        ] A problem occurred configuring root project 'android'.
[        ] > Could not resolve all artifacts for configuration ':classpath'.
[        ]    > Could not find gradle-4.1.0.jar (com.android.tools.build:gradle:4.1.0).
[  +10 ms]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.jar
[  +19 ms]    > Could not find builder-4.1.0.jar (com.android.tools.build:builder:4.1.0).
[  +47 ms]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/4.1.0/builder-4.1.0.jar
[        ]    > Could not find aaptcompiler-4.1.0.jar (com.android.tools.build:aaptcompiler:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/aaptcompiler/4.1.0/aaptcompiler-4.1.0.jar
[        ]    > Could not find bundletool-0.14.0.jar (com.android.tools.build:bundletool:0.14.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/bundletool/0.14.0/bundletool-0.14.0.jar
[        ]    > Could not find manifest-merger-27.1.0.jar (com.android.tools.build:manifest-merger:27.1.0).
[   +1 ms]      Searched in the following locations:
[   +4 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/27.1.0/manifest-merger-27.1.0.jar
[        ]    > Could not find lint-gradle-api-27.1.0.jar (com.android.tools.lint:lint-gradle-api:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-gradle-api/27.1.0/lint-gradle-api-27.1.0.jar
[        ]    > Could not find lint-model-27.1.0.jar (com.android.tools.lint:lint-model:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-model/27.1.0/lint-model-27.1.0.jar
[        ]    > Could not find sdk-common-27.1.0.jar (com.android.tools:sdk-common:27.1.0).
[        ]      Searched in the following locations:
[  +28 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/27.1.0/sdk-common-27.1.0.jar
[        ]    > Could not find aapt2-proto-4.1.0-6503028.jar (com.android.tools.build:aapt2-proto:4.1.0-6503028).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2-proto/4.1.0-6503028/aapt2-proto-4.1.0-6503028.jar
[        ]    > Could not find crash-27.1.0.jar (com.android.tools.analytics-library:crash:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/crash/27.1.0/crash-27.1.0.jar
[        ]    > Could not find gradle-api-4.1.0.jar (com.android.tools.build:gradle-api:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-api/4.1.0/gradle-api-4.1.0.jar
[        ]    > Could not find databinding-compiler-common-4.1.0.jar (androidx.databinding:databinding-compiler-common:4.1.0).
[        ]      Searched in the following locations:
[   +3 ms]          https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-compiler-common/4.1.0/databinding-compiler-common-4.1.0.jar
[   +4 ms]    > Could not find builder-model-4.1.0.jar (com.android.tools.build:builder-model:4.1.0).
[  +13 ms]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-model/4.1.0/builder-model-4.1.0.jar
[        ]    > Could not find builder-test-api-4.1.0.jar (com.android.tools.build:builder-test-api:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/builder-test-api/4.1.0/builder-test-api-4.1.0.jar
[        ]    > Could not find ddmlib-27.1.0.jar (com.android.tools.ddms:ddmlib:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/ddms/ddmlib/27.1.0/ddmlib-27.1.0.jar
[  +50 ms]    > Could not find signflinger-4.1.0.jar (com.android:signflinger:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/signflinger/4.1.0/signflinger-4.1.0.jar
[        ]    > Could not find zipflinger-4.1.0.jar (com.android:zipflinger:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/zipflinger/4.1.0/zipflinger-4.1.0.jar
[        ]    > Could not find tracker-27.1.0.jar (com.android.tools.analytics-library:tracker:27.1.0).
[        ]      Searched in the following locations:
[   +1 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/tracker/27.1.0/tracker-27.1.0.jar
[        ]    > Could not find sdklib-27.1.0.jar (com.android.tools:sdklib:27.1.0).
[  +10 ms]      Searched in the following locations:
[   +6 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/sdklib/27.1.0/sdklib-27.1.0.jar
[        ]    > Could not find layoutlib-api-27.1.0.jar (com.android.tools.layoutlib:layoutlib-api:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/layoutlib/layoutlib-api/27.1.0/layoutlib-api-27.1.0.jar
[        ]    > Could not find dvlib-27.1.0.jar (com.android.tools:dvlib:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/dvlib/27.1.0/dvlib-27.1.0.jar
[        ]    > Could not find repository-27.1.0.jar (com.android.tools:repository:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/repository/27.1.0/repository-27.1.0.jar
[   +7 ms]    > Could not find shared-27.1.0.jar (com.android.tools.analytics-library:shared:27.1.0).
[   +8 ms]      Searched in the following locations:
[   +1 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/shared/27.1.0/shared-27.1.0.jar
[   +3 ms]    > Could not find common-27.1.0.jar (com.android.tools:common:27.1.0).
[   +1 ms]      Searched in the following locations:
[   +1 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/common/27.1.0/common-27.1.0.jar
[        ]    > Could not find transform-api-2.0.0-deprecated-use-gradle-api.jar (com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api).
[  +59 ms]      Searched in the following locations:
[   +2 ms]
https://dl.google.com/dl/android/maven2/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-api.jar
[   +5 ms]    > Could not find jetifier-processor-1.0.0-beta09.jar (com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta09).
[        ]      Searched in the following locations:
[   +4 ms]          https://dl.google.com/dl/android/maven2/com/android/tools/build/jetifier/jetifier-processor/1.0.0-beta09/jetifier-processor-1.0.0-beta09.jar
[        ]    > Could not find jetifier-core-1.0.0-beta09.jar (com.android.tools.build.jetifier:jetifier-core:1.0.0-beta09).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/jetifier/jetifier-core/1.0.0-beta09/jetifier-core-1.0.0-beta09.jar
[        ]    > Could not find protos-27.1.0.jar (com.android.tools.analytics-library:protos:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/analytics-library/protos/27.1.0/protos-27.1.0.jar
[        ]    > Could not find core-proto-0.0.2-dev.jar (com.google.test.platform:core-proto:0.0.2-dev).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/google/test/platform/core-proto/0.0.2-dev/core-proto-0.0.2-dev.jar
[        ]    > Could not find apkzlib-4.1.0.jar (com.android.tools.build:apkzlib:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/apkzlib/4.1.0/apkzlib-4.1.0.jar
[        ]    > Could not find apksig-4.1.0.jar (com.android.tools.build:apksig:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/build/apksig/4.1.0/apksig-4.1.0.jar
[        ]    > Could not find annotations-27.1.0.jar (com.android.tools:annotations:27.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/com/android/tools/annotations/27.1.0/annotations-27.1.0.jar
[        ]    > Could not find databinding-common-4.1.0.jar (androidx.databinding:databinding-common:4.1.0).
[        ]      Searched in the following locations:
[        ]          https://dl.google.com/dl/android/maven2/androidx/databinding/databinding-common/4.1.0/databinding-common-4.1.0.jar
[        ]    > Could not find baseLibrary-4.1.0.jar (com.android.databinding:baseLibrary:4.1.0).
[        ]      Searched in the following locations:
[  +14 ms]          https://dl.google.com/dl/android/maven2/com/android/databinding/baseLibrary/4.1.0/baseLibrary-4.1.0.jar
[  +15 ms] * 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 2m 15s
[+1017 ms] Running Gradle task 'assembleDebug'... (completed in 137.9s)
[   +9 ms] Exception: Gradle task assembleDebug failed with exit code 1    

I'm sorry, I'm just a very beginner but I tried to downgrade the gradle, reinstall android studio and vscode and sdk but still no luck.

here is my build.gradle:

    buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
        
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {      
        google()
        jcenter()
        
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

note that I didn't Install any emulator but I installed android studio to install the sdk. and it downloaded: enter image description here

enter image description here

here is grdale.properties :

  org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true

here is screenshot of proxy setting : HTTP proxy

and here is a scrennshot when I run gradle build --warning-mode=all : and it gave me No dependencies enter image description here

wrapper.properties :

 #Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip

After trying the solution a new error has occurred:

    Building with sound null safety

Running Gradle task 'assembleRelease'...


FAILURE: Build failed with an exception.



* Where:

Build file 'C:\Users\hh\StudioProjects\untitled1\android\app\build.gradle' line: 26



* What went wrong:

A problem occurred evaluating project ':app'.

> Could not resolve all artifacts for configuration 'classpath'.

   > Could not find transform-api-2.0.0-deprecated-use-gradle-api.jar (com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api).

     Searched in the following locations:

         https://dl.google.com/dl/android/maven2/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-ap
i.jar



* 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 49s
Running Gradle task 'assembleRelease'...                           52.0s
Gradle task assembleRelease failed with exit code 1

1 Answers1

0

For some reason, it cannot get the .jar files from the repository. Let's check the access to the resource, try one of the links, for example: https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.0/gradle-4.1.0.jar If the download has started, then the resource is available.

Try this:

1.Open settings in studio and find this: Repository settings. You should have this all urls here

2.Edit gradle file:

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
    maven { url 'https://dl.google.com/dl/android/maven2' }
    google()
    jcenter()

}

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
    maven { url 'https://dl.google.com/dl/android/maven2' }
    google()
    jcenter()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
}

3.Add these repositories also in flutter.gradle:

repositories {
 mavenCentral()
 maven { url 'https://jitpack.io' }
 maven { url 'https://dl.google.com/dl/android/maven2' }
 google()
 jcenter()
}

4.Close Android Studio

5.Remove folder .gradle in C:\Users{Your User}

6.Open Android Studio and Build again

Leonid
  • 999
  • 1
  • 7
  • 14
  • thank you for answering, I edited the question and added the gradle code. – HasanMHallak Aug 07 '21 at 11:20
  • @HasanMHallak I edited the answer, look repository settings – Leonid Aug 07 '21 at 11:21
  • still the same error. if the url is working can't I download everything it needs and work offline? I'm sorry I'm still newbie and didn't even write any code yet. I just download everything as instructed in the course and tried to run the Demo app that came with flutter. android studio is 2020.3.1.22 win7 x64 and flutter 2.2.3 stable. – HasanMHallak Aug 07 '21 at 13:58
  • @HasanMHallak You can download this files, but it will take a long time, since you need to include a lot of .jar files. Better to solve this problem now and not deal with it later :) – Leonid Aug 07 '21 at 14:05
  • Try add maven line from my answer to your gradle file – Leonid Aug 07 '21 at 14:09
  • still the same. is it possible that I'm running a VPN so I can open these sites? because otherwise it gives me error 403 – HasanMHallak Aug 07 '21 at 14:21
  • I tried ```gradle --stacktrace``` and it gave me this: 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.7/userguide/command_line_interface.html#sec:command_line_warnings – HasanMHallak Aug 07 '21 at 14:28
  • Can you send screen of System Settings -> HTTP Proxy and add code from gradle.properties file – Leonid Aug 07 '21 at 14:29
  • "Deprecated Gradle features..." - it is ok – Leonid Aug 07 '21 at 14:30
  • And add please code from gradle-wrapper.properties – Leonid Aug 07 '21 at 14:47
  • @HasanMHallak Have you tried disabling auto-detect proxies in the settings of android studio? – Leonid Aug 07 '21 at 15:02
  • @HasanMHallak Is your VPN enabled in your browser or on the system? – Leonid Aug 07 '21 at 15:18
  • I use Hotspot shield. I think it tunnel the whole system. – HasanMHallak Aug 07 '21 at 15:23
  • @HasanMHallak Do it all after the sign "Try this" in my answer point by point. – Leonid Aug 07 '21 at 15:59
  • I did as you toled me above and a new error has occurred. but it seems much shorter than the first one. I edited my question. – HasanMHallak Aug 07 '21 at 18:08
  • @HasanMHallak can you try answer from this question? https://stackoverflow.com/questions/63157065/could-not-find-com-android-tools-buildgradle4-0-1-or-any-version – Leonid Aug 07 '21 at 20:31
  • thank you for your help. I tried to changed the proxy setting and nothing happened. but I managed to fix the problem by editing on a file called ```flutter.gradle``` and add the same repositories you mentioned in your answer . the only thing that remains is I have to edit the ```build.gradle``` every time I start a new project. isn't there any workaround for this? – HasanMHallak Aug 08 '21 at 16:37
  • @HasanMHallak If it does not work, then yes, you need to add all these repositories in the new project. – Leonid Aug 08 '21 at 16:41
  • @HasanMHallak Happy to help :) Do you confirm my answer? I add words about flutter.gradle – Leonid Aug 08 '21 at 16:43
  • okay then. guess I'll have to add them every time. thank you again, I just confirm your answer. – HasanMHallak Aug 08 '21 at 17:32