Gradle sync failed: Could not find method defaultConfig() - android

In the first instance my problem was Cause 1: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
but this has escalated since then and now my gradle is broken.
this is the error I am getting:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\stackstorage\android projecten\Converter\build.gradle' line: 26
* What went wrong:
A problem occurred evaluating root project 'Converter'.
> Could not find method defaultConfig() for arguments [build_7komq7i2k7pl5720grjx3kada$_run_closure2#b894d83] on root project 'Converter' of type org.gradle.api.Project.
* 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
CONFIGURE FAILED in 0s
Could not find method defaultConfig() for arguments [build_7komq7i2k7pl5720grjx3kada$_run_closure2#b894d83] on root project 'Converter' of type org.gradle.api.Project.
Open File
event log:
12:13 Gradle sync started with IDEA sync
12:13 Gradle sync failed: Could not find method defaultConfig() for arguments [build_7komq7i2k7pl5720grjx3kada$_run_closure2#55d7744a] on root project 'Converter' of type org.gradle.api.Project.
Consult IDE log for more details (Help | Show Log) (287 ms)
12:13 NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
12:13 Gradle sync started with IDEA sync
12:13 Gradle sync failed: Could not find method defaultConfig() for arguments [build_7komq7i2k7pl5720grjx3kada$_run_closure2#b894d83] on root project 'Converter' of type org.gradle.api.Project.
Consult IDE log for more details (Help | Show Log) (230 ms)
12:13 NDK Resolution Outcome: Project settings: Gradle model version=5.4.1, NDK version is UNKNOWN
I am unsure what code I need to post for this to get helped but I've seen people posting their build.gradle and gradle.properties, so i'll post mine.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
task clean(type: Delete) {
delete rootProject.buildDir
}
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx4608m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
Thanks in advance to anyone willing to help. I kinda messed up here.

Check your app> build.gradle file. there will be defaultConfig() tag like this
defaultConfig {
applicationId "com.example.myApp"// your appId
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

In android studio, go to your project. Make sure you are in the view mode "Android". Just like this image:
Should be like this in android studio
Go to Gradle-Scripts -> build.gradle (module:app) and make sure it is composed similarly to this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "your app id"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//your dependencies
}

Move defaultConfig{} from gradle project to build.gradle's app module inside android tag.
Should be similar to this
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
mavenCentral()
}
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Related

Flutter : Getting appcenter:verifyReleaseResources Error When Trying to Build in AppCenter

I have followed this blog to build my app on AppCenter
Exactly did the same process
https://medium.com/#maite.daluz11/deploy-flutter-apps-using-appcenter-ec28e8d940bf
APPCENTER BUILD OUTPUT IS SHOWING
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':appcenter:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
/Users/runner/.gradle/caches/transforms-2/files-2.1/a528b13ac93e64cafa3d0480e2c93207/core 1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/fontVariationSettings not found.
/Users/runner/.gradle/caches/transforms-2/files-2.1/a528b13ac93e64cafa3d0480e2c93207/core-1.1.0/res/values/values.xml:142:5-173:25: AAPT: error: resource android:attr/ttcIndex not found.
BUILD FAILED in 2m 16s
Running Gradle task 'assembleRelease'... 137.7s (!)
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
✏️ Creating `android/settings_aar.gradle`... 1ms
✓ `android/settings_aar.gradle` created successfully.
Building plugin appcenter...
Running Gradle task 'assembleAarRelease'... 35.1s
✓ Built build/app/outputs/repo.
Building plugin appcenter_analytics...
Running Gradle task 'assembleAarRelease'... 2.7s
✓ Built build/app/outputs/repo.
Building plugin appcenter_crashes...
Running Gradle task 'assembleAarRelease'... 2.4s
✓ Built build/app/outputs/repo.
Building plugin flutter_plugin_android_lifecycle...
Running Gradle task 'assembleAarRelease'... 20.9s
Gradle 5.4.1
Resolved com.android.tools.build:gradle:3.5.0 in :classpath
Resolved androidx.annotation:annotation:1.1.0 in :releaseRuntimeClasspath
Resolved io.flutter:flutter_embedding_release:1.0.0-ae90085a8437c0ae94d6b5ad2741739ebc742cb4 in :releaseCompileClasspath
Resolved androidx.annotation:annotation:1.1.0 in :releaseCompileClasspath
Resolved androidx.annotation:annotation:1.1.0 in :releaseCompileClasspath
Resolved com.android.tools.lint:lint-gradle:26.5.0 in :lintClassPath
/Users/runner/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.11/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:8: error: package androidx.lifecycle does not exist
import androidx.lifecycle.Lifecycle;
^
/Users/runner/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-1.0.11/android/src/main/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapter.java:22: error: cannot find symbol
public static Lifecycle getActivityLifecycle(
^
symbol: class Lifecycle
location: class FlutterLifecycleAdapter
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
BUILD FAILED in 18s
The plugin flutter_plugin_android_lifecycle could not be built due to the issue above.
My android/app/build.gradle is:
android {
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_tls_identity"
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
def appCenterSdkVersion = '4.0.0'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
}
My android/build.gradle is:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
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
}
My android/app/appcenter-post-clone.sh is:
#!/usr/bin/env bash
#Place this script in project/android/app/
cd ..
#fail if any command fails
set -e
#debug log
set -x
cd ..
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH
flutter channel stable
flutter doctor
echo "Installed flutter to `pwd`/flutter"
#build APK
#if you get "Execution failed for task ':app:lintVitalRelease'." error, uncomment next two lines
#flutter build apk --debug
#flutter build apk --profile
flutter build apk --release
#if you need build bundle (AAB) in addition to your APK, uncomment line below and last line of this script.
#flutter build appbundle --release --build-number $APPCENTER_BUILD_ID
#copy the APK where AppCenter will find it
mkdir -p android/app/build/outputs/apk/; mv build/app/outputs/apk/release/app-release.apk $_
#copy the AAB where AppCenter will find it
#mkdir -p android/app/build/outputs/bundle/; mv build/app/outputs/bundle/release/app-release.aab $_
My gradle.properties is
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
My pubspec.yaml dependencies is
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
path_provider:
image_picker:
appcenter:
appcenter_analytics:
appcenter_crashes:
My gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
Solution to the error is;
1 - Open your android/build.gradle & add the following code under your last subprojects
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 28 --> This is the version in my android/app/build.gradle
buildToolsVersion "28.0.3"
}
}
}
}
2 - Right click to the android[flutter_app_name] folder & go to Flutter -> Open Android module in Android Studio
3 - Under your Project folder open android -> android [appcenter] -> build.gradle & make sure the following Versions are same with the one's in your android/app/build.gradle
compileSdkVersion
buildToolsVersion
minSdkVersion
targetSdkVersion
group 'com.aloisdeniel.flutter.appcenter'
version '1.0-SNAPSHOT'
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
rootProject.allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 28 --> Make sure this version is same with the one in your android/app/build.gradle
buildToolsVersion '28.0.3' --> Make sure this version is same with the one in your android/app/build.gradle
defaultConfig {
minSdkVersion 21 --> Make sure this version is same with the one in your android/app/build.gradle
targetSdkVersion 28 --> Make sure this version is same with the one in your android/app/build.gradle
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}
dependencies {
def appCenterSdkVersion = '1.10.0'
implementation "com.microsoft.appcenter:appcenter:${appCenterSdkVersion}"
}
}
4 - Do the same process for the android [appcenter_analytics] & android [appcenter_crashes].
5 - In terminal type flutter clean and after it finishes type flutter build apk.

Define Checkstyle Task with android gradle plugin 3.4.0

I upgraded my build.gradle file to android gradle plugin 3.4.0 with gradle 5.11.
My build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
android {
compileSdkVersion 28
buildToolsVersion buildVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "myapp"
minSdkVersion 21
targetSdkVersion 28
versionName "5.20.0"
versionCode 520
}
dataBinding {
enabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "com.android.support:support-v4:$supportLibVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
task checkstyle(type: Checkstyle) {
source 'src/'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
reports {
xml {
destination "build/outputs/reports/checkstyle-results.xml"
}
}
group = JavaBasePlugin.VERIFICATION_GROUP
description = 'Performs checkstyle verification on the code.'
}
task checkstyleReport(dependsOn: 'checkstyle', group: JavaBasePlugin.VERIFICATION_GROUP) {
if (file("build/outputs/reports/checkstyle-results.xml").exists()) {
ant.xslt(in: "build/outputs/reports/checkstyle-results.xml",
style: "./config/checkstyle/checkstyle.xsl",
out: "build/outputs/reports/checkstyle-results.html"
)
}
}
When syncing I get the following error message:
FAILURE: Build failed with an exception.
Where: Build file '/Users/cs/Development/project/app/build.gradle'
What went wrong: A problem occurred evaluating project ':app'.
Could not find method destination() for arguments [build/outputs/reports/checkstyle-results.xml] on Report xml of type
org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport.
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 1s ERROR: Gradle DSL method not found: 'destination()'
Possible causes: The project 'project' may be using
a version of the Android Gradle plug-in that does not contain the
method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to
version 3.4.0 and sync project
The project 'project' may be using a version of
Gradle that does not contain the method. Open Gradle wrapper file
The build file may be missing a Gradle plugin. Apply Gradle plugin
The error points to this lines:
reports {
xml {
destination "build/outputs/reports/checkstyle-results.xml"
}
}
Has the syntax for destination been changed in gradle?
Solution
reports {
xml {
destination file("build/outputs/reports/checkstyle-results.xml")
}
}
The method used to take an Object, but now requires a File type as a parameter - hence the parameter error.
So passing in a file instead solves the problem.
You can see the expected parameter types here:
https://docs.gradle.org/current/javadoc/org/gradle/api/reporting/ConfigurableReport.html#setDestination-java.io.File-

Unable to publish Android library project on JitPack

I made a small library for Android which I uploaded on my public Github repositroy. The library project contains also a sample app. To enable building on JitPack I followed JitPack's own instructions.
Now that i try build it remotely with JitPack i get following error:
WARNING:
Gradle 'install' task not found. Please add the 'maven' or 'android-maven' plugin.
See the documentation and examples: https://jitpack.io/docs/
Adding maven plugin
Found android library build file in Library
Running: gradle clean -Pgroup= -Pversion=v1.2 install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Djavax.xml.accessExternalSchema=all
Gradle version Gradle 3.1
FAILURE: Build failed with an exception.
* What went wrong:
Task 'clean' not found in root project 'build'.
* Try:
Run gradle tasks to get a list of available tasks. 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.532 secs
EXIT_CODE=1
2017-03-22T19:01:33.352614259Z
Exit code: 1
No build artifacts found
Here is the root build file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Build file for the library:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group=
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
}
}
Build file for the sample app:
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.2.0'
compile project(':Library')
}
The project is missing a settings.gradle file where you include the library:
include ':Library'
Would also recommend adding the gradle wrapper so that JitPack builds with the correct Gradle version.
Example project: https://github.com/jitpack/android-example

Getting error while adding Facebook SDK in build.gradle

I am working on a project where I need to implement facebook login. For that purpose I followed the steps from the developer website as mentioned. But unfortunately getting build error after adding'com.facebook.android:facebook-android-sdk:4.1.0' in build.gradleas follows
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.facebook"
minSdkVersion 11
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Error log which I am getting:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.facebook.android:facebook-android-sdk:4.1.0.
Required by: ExampleApp:app:unspecified
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
Please help me to resolve this issue which I am facing right for a couple of days. I am really helpless and stuck up with the solutions. Any kind of suggestions would be much useful to fix my issue.
Your log gives the answer:
No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
Gradle is in offline mode, so it cannot download a new version of your library.
Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle
and disable "Offline work".
Preferences can be accessed from here:
You do not need repositories in this gradle file as you should have one "global" build.gradle so remove this entry from module's grade file. And you should also check what repository is set there as it should be jcenter() not mavenCentral() as the latter is replaced with jcenter() for some time now.
allprojects {
repositories {
jcenter()
}
}

Gradle failed to refresh Android Studio

Ive been installing and re-installing AndroidStudio since i keep getting the error
> Gradle 'android' project refresh failed:
> Open quote is expected for attribute "{1}" associated with an element type "language".
All of my group members can open up the project without receiving this error except me.I am in dire need of help,i just want to finish my group project for the semester.Thank you for your help.
settings.gradle
include ':app'
build.gradle in the app folder
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.android.support:support-v4:18.0.0'
files('libs/json-simple-1.1.1.jar')
compile files('libs/json-simple-1.1.1.jar')
}
build.gradle in the gradle folder
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Update:did another re-intstall of Android Studio and now its giving me this error.
Failed to refresh Gradle project 'android'
Out of memory: Java heap space. Configure Gradle memory settings using '-Xmx' JVM option (e.g. '-Xmx2048m'.)
Please fix the project's Gradle settings.
Gradle settings
You might have typed closed quote (“) instead of open quote("). Change the quotes at start and end of attribute.

Categories

Resources