Can't find android block in build.gradle of Flutter project - android

I created a flutter project using flutter create my_app, which gives me a perfectly working Flutter Demo Home Page with a counter example.
I am now testing deployment of the app following the official documentation. I have created a keystore and a key.properties file as required, but I can't find the android block in the build.grandle file mentioned here.
I tried building the app and starting it on my phone but the build.gradle is still missing the android block.
Should I add it manually or did I possibly miss a step?
EDIT:
This is my build.gradle file
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
}

The file is android/app/build.gradle and not /android/build.gradle.
Sorry

Related

Kotlin version is not update in gradle.build file

I tried many times to update kotlin version but it shows me the old version instead of the latest one. This is a flutter project that tries to run the project. Here is a screenshot.
Please check and let me know what's wrong with it.
Thank you.
Error in this image
i need this solution.
buildscript {
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10'
}
}
//$kotlin_version removed it to 1.5.31
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}

Problems in Android repository Flutter TensorFlow-lite by Bintray 502

When I compile my Android Flutter application I get this error
Could not determine the dependencies of task ':app:processDebugResources'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not resolve org.tensorflow:tensorflow-lite:+.
Required by:
project :app > project :tflite
> Failed to list versions for org.tensorflow:tensorflow-lite.
> Unable to load Maven meta-data from https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/maven-metadata.xml.
> Could not get resource 'https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/maven-metadata.xml'.
> Could not GET 'https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/maven-metadata.xml'. Received status code 502 from server: Bad Gateway
Bintray is down for this https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/maven-metadata.xml
After this problem try to change the repository in android/build.gradle from Jcenter() to mavenCentral()
my android/build.gradle
buildscript {
repositories {
mavenCentral()
google()
//jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.4'
//classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.gms:google-services:4.3.4'
}
}
allprojects {
repositories {
mavenCentral()
//google()
//jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
After this change, the error continues to appear since it comes from the Google Bintray repository, but I cannot remove Google in the repositories because I use some services, what should be done to solve the problem? I know that Bintray has been down for about 10 days but I want to know how mavenCentral() can be implemented correctly for the tensor-flow-lite package.
I am totally new and I do not know if the maven-metadata can be downloaded and how to implement it, so I need to know how to solve these dependencies, it is very complex for me.
[UPDATE]
Problems with dependencies by Bintray in Android [502] solved. IDE Android Studio version 4.1.1 .
After waiting for a response from bintray and contacting me by email, I realized that finally the bintray server would be blocked since Jfrog is migrating the artifacts to Artifactory, the email response was the following
"As stated in the blog post, Bintray will be sunsetted indefinitely and will not be a functional tool as we migrated the Bintray toolset into Artifactory.
"
This is the blog post for bintray is down
After this, it is very likely that bintray will not be available again, or although as the email response says, migrating the artifacts would take a long time if Jfrog considers lifting the bintray server.
To solve this and it works perfectly is:
[1.] Check what artifacts your project requires
[2.] Import the repositories containing the artifacts to build.gradle in the repositories
[3.] Comment (if you wish in hope that google bintray returns) the google repository ().
[4.] Verify the correct implementation of the dependencies
All this will make the repositories look for the dependency that was in bintray and occupy it from the raised server that you have chosen.
Personally my artifacts were in the maven() repositories so I made this change in the build.gradle.
Replace google () and jCenter () in repositories with maven ().
build.gradle
buildscript {
repositories {
mavenCentral()
maven {
url 'https://maven.google.com'
}
//mavenCentral()
//google()
//jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.1.0'
//classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.gms:google-services:4.3.4'
}
}
allprojects {
repositories {
mavenCentral()
maven {
url 'https://maven.google.com'
}
//mavenCentral()
//google()
//jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This got them repositories they needed...
Check if you have Google Play servecies installed, it solved some problems for me.
Flutter plugin
There is a similar answer similarthat helps this, but it does not correspond to the Android IDE and this one requires a few more small steps.
Flutter plugins (some) despite the repository changes in build.gradle by maven () in the general project, will continue to search google.bintray repositories because the plugin itself has this repository in its build.gradle, surely this error will appear if not the following is solved.
> Unable to load Maven meta-data from https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/maven-metadata.xml.
This is an example with flutter plugin "tflite".
To solve this, you have to look for the flutter plugins obtained by pubspec.yaml.
NOTE: It is important that these changes are simply a temporary trick until google fixes the problem of its storage in bintray or although, until there are versions directed to maven (), at least this allows the application to be compiled and it works, in my case it was Well, but I say again, it is a trick and should not be done.
[1.]At the project level, look for the flutter plugins in External libraries>Flutter pluggins>Search plugging error(example tflite).
[2.]Open the plugin and modify its build.gradle, changing the repositories where the artifact is on another server, in my case it was still in maven ().
Change the version of the artifact in the dependencies, if a + appears, delete it, leave a fixed version.
Note: the "includeGroup" in repository is added so that the plugging does not look for the bintray plugin again, if you delete this or the google repository (), I don't know why the plugging keeps looking for that path, so it is better to leave it excluded so that it looks in the self-specified repositories.
build.gradle of plugging (example tflite)
group 'sq.flutter.tflite'
version '1.0-SNAPSHOT'
buildscript {
repositories {//Changes here ***************
mavenCentral()
maven {
url 'https://maven.google.com'
}
google {
content {
includeGroup "https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/0.0.1/tensorflow-lite-0.0.1.pom"
}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
rootProject.allprojects {
repositories {
mavenCentral()
maven {
url 'https://maven.google.com'
}
google {
content {
includeGroup "https://google.bintray.com/exoplayer/org/tensorflow/tensorflow-lite/0.0.1/tensorflow-lite-0.0.1.pom"
}
}
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
dependencies {//Changes here, delete 0.0.5+ to 0.0.5 example..
compile 'org.tensorflow:tensorflow-lite:0.0.1-gpu-experimental'
}
}
Reminder: remember to check the repository well and in the dependencies delete the version that contains +, example 0.0.5+ and change it for an existing fixed version example 0.0.2.
If your editor says that the file does not belong to your project, select "I want to edit this file anyway".
All these changes will cause the Flutter pluggin itself to search a server that has a complement and is functional while google does not fix this or launches a new version, possibly if you update the pubspec.yaml you can revert your own changes in the pluggin, so be careful , but this should compile you for now.
I can confirm this is working fix.Already upvoted your answer.
This is tflite build gradle plugin that i modified for my tensorflow-lite project
group 'sq.flutter.tflite'
version '1.0-SNAPSHOT'
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
dependencies {
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
}
}
This is my current build gradle. I changed all jcenter to mavencentral to make it work. My project now work both offline and online.
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google() // Google's Maven repository
mavenCentral() // removed jcenter add this
}
dependencies {
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google() // Google's Maven repository
mavenCentral() // removed jcenter add this
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
By the im using TFlite plugin version 1.1.1
Gradle wrapper version
distributionUrl = https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
I have Same Error.In my case i used the simple method to solve that problem.
Go to External libraries -> Flutter pluggins -> tflite-1.1.2 -> android -> build.gradle
Change the dependencies
compile 'org.tensorflow:tensorflow-lite:1.1.2' &
compile 'org.tensorflow:tensorflow-lite-gpu:1.1.2'
Change into Like this
implementation 'org.tensorflow:tensorflow-lite:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
It's work for me.Try this and Thanks you.

Set up Google Play services in my flutter app

I want to modify the MainActivity.java file, for a custom android implementation. To do that, i need to include google libraries, like LocationServices.
Eg, to use ..
import com.google.android.gms.location.LocationServices;
I looked at the official google documentation
https://developers.google.com/android/guides/setup
And I can see this line, which must be added in build.gradle file.
dependencies {
implementation 'com.google.android.gms:play-services-location:18.0.0'
}
I try to add this line in my "build.gradle" file, but maybe it's wrong
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'
}
}
When I run "gradlew build", I get this error:
Could not find method implementation() for arguments [com.google.android.gms:play-services-location:18.0.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is the default "build.gradle" file for flutter.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
What's the correct way to import those google libs ?
Thanks
You added the dependency to the wrong file.
In the photo, you can see the location of the correct build.gradle file and the line where you will add the dependency.
I took a screenshot for you;

Could not find method implementation Flutter Android app

I have a brand new Flutter application in which I am trying to add Notification from native Android service receiver.
When I write the code related to NotificationCompat, Android Studio suggest to add com.android.support:support-compat:28.0.0 dependency to build.gradle file. But once I add this dependency in the build.gradle file it starts showing gradle build failed errors.
Error:
Could not find method implementation() for arguments
[com.android.support:support-compat:28.0.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Gradle file
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
implementation 'com.android.support:support-compat:28.0.0'
}
Thanks for your time
I had the same issue with firebase-messaging the problem has gone once I have moved the dependency from build.gradle to app/build.gradle

Firebase Crashlytics build error: "could not find io.fabric.tools:gradle:1.26.1"

I was trying to integrate Firebase Crashlytics on my react native app but got this error while building the app.
What went wrong:
A problem occurred configuring root project 'MyApp'.
Could not resolve all artifacts for configuration ':classpath'.
Could not find io.fabric.tools:gradle:1.26.1.
Searched in the following locations:
https://dl.google.com/dl/android/maven2/io/fabric/tools/gradle/1.26.1/gradle-1.26.1.pom https://dl.google.com/dl/android/maven2/io/fabric/tools/gradle/1.26.1/gradle-1.26.1.jar
https://repo.maven.apache.org/maven2/io/fabric/tools/gradle/1.26.1/gradle-1.26.1.pom
https://repo.maven.apache.org/maven2/io/fabric/tools/gradle/1.26.1/gradle-1.26.1.jar
https://jcenter.bintray.com/io/fabric/tools/gradle/1.26.1/gradle-1.26.1.pom
https://jcenter.bintray.com/io/fabric/tools/gradle/1.26.1/gradle-1.26.1.jar
Required by:
project :
Try:
I've added classpath 'io.fabric.tools:gradle:1.26.1' in dependencies and
maven {
url 'https://maven.fabric.io/public'
}
in repositories in build.gradle as suggested in documentation.
Before, I got the same issue because I moved the url 'https://maven.fabric.io/public' to the wrong place
I guess you guy also same. My working build.grande is
buildscript {
repositories {
google()
jcenter()
// Additional repository for fabric resources
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
// Add fabric classpath
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
As per the documentation of the fabric integration.
Try using this as a sub-library of the project.
In your app's Gradle mention the below code. It will work.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
You have to ensure that everything in the documentation that should be in the project-level build.gradle file is there and make sure everything that should be in app-level build.gradle file is there.
Do not interchange anything.

Categories

Resources