Android Studio :: Gradle Scripts Error Android() - android

I use this following script under my current android project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
android {
compileSdkVersion 11
buildToolsVersion "11.0"
defaultConfig {
applicationId "com.stackoverflow.answer"
minSdkVersion 11
targetSdkVersion 11
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
But then found this error message.
How to solve this ?

The android block should be within a module build.gradle that contains apply plugin: 'com.android.application', and not in the root build.gradle file.
Example:
root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
module build.gradle (could be within the app folder):
apply plugin: 'com.android.application'
android {
compileSdkVersion 11
buildToolsVersion "11.0"
defaultConfig {
applicationId "com.stackoverflow.answer"
minSdkVersion 11
targetSdkVersion 11
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

Related

Method classpath() can not be found

I have the following error :
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method classpath() for arguments [com.github.dcendents:android-maven-gradle-plugin:1.4.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Here's my build.gradle (App)
apply plugin: 'com.android.application'
repositories {
google()
jcenter()
}
dependencies {
implementation 'com.google.firebase:firebase-appindexing:11.6.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.android.tools.build:gradle:4.1.0'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.xxx"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "0.01"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
And the build.gradle
// 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.4.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
allprojects {
repositories {
google()
jcenter()
}
}
}
what did I do wrong ?
Thank you for your help.

Process 'command '/home/bgn-dev/Android/Sdk/build-tools/28.0.3/aapt'' finished with non-zero exit value 1

After migrating my project to Android X, there was an error like in the title. gradle.app is as follows. I would be very happy if you could help. Thank you.
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.burakgon.hyperaudio"
minSdkVersion 16
targetSdkVersion 28
versionCode 1005
versionName "1005d"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
applicationVariants.all { variant ->
variant.outputs.all {
def version = variant.versionName
outputFileName = "hyperaudio-${version}.apk"
}
}
buildToolsVersion '28.0.3'
}
repositories {
maven {
url "https://jitpack.io"
}
}
ext {
supportLibVersion = '28.0.0' // variable that can be referenced to keep support libs consistent
}
You need to add the google() repo in the top level gradle file and also it should be before jcenter():
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.0.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}

Crashlytics - Unable to get crash reports when the app crashes while not connected to android studio

I'm using crashytics from Fabric.io in my app.
Here's how I have initialised it in my MainActivity.java at the very last of onCreate() method:
Fabric.with(this, new Crashlytics());
Here's build.gradle (Project: abc) file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public'}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'io.fabric.tools:gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://dl.bintray.com/hani-momanii/maven"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here's build.gradle (Module: app) file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.xxx.abc"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
mavenCentral()
maven {
url "https://jitpack.io"
}
maven { url 'https://maven.fabric.io/public' }
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.crashlytics.sdk.android:crashlytics:2.6.6#aar') {
transitive = true;
}
}
apply plugin: 'com.google.gms.google-services'
and
<meta-data
android:name="io.fabric.ApiKey"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxx"
/> is defined in the AndroidManifest.xml between <application> tags.
The problem is that I'm unable to get the crash reports whenever the app crashes while not connected to Android Studio though I get the reports when the app crashes while connected to it.
Why is this happening and how can I get the crash reports each and every time the app crashes whether connected to Android Studio or not?
Remove from Activity and put inside Application class
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
}
Don't forget to add name in Application tag of manifest.xml
<application
...
android:name=".MyApplication"
...
</application>

Gradle not working with android studio

I've tried everything I've found on the ointernet with all the error messages i found. Styles are missing, gradle can't sync and nothing is working. Help please
build.gradle (Project:MyApplication)
buildscript {
repositories {
jcenter()
}
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()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.utente.myapplication"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
maven { url 'http://repo1.maven.org/maven2' }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.3'
}

Cannot make Android databinding plugin work

I am trying to make use of the android databinding plugin with no luck so far.
I am using: Gradle 2.2.1; Intellij IDEA 15.
Project level build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath "com.android.databinding:dataBinder:1.0-rc2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Module build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
buildscript {
repositories {
jcenter()
}
dependencies {
}
}
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.app4.app4"
minSdkVersion 10
targetSdkVersion 10
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
}
I got few different errors while trying to change plugins' versions; the error I am getting now is "Error:Gradle: A problem occurred configuring project ':app4'.
Failed to notify project evaluation listener.
android.databinding.tool.LayoutXmlProcessor.(Ljava/lang/String;Landroid/databinding/tool/writer/JavaFileWriter;IZLandroid/databinding/tool/LayoutXmlProcessor$OriginalFileLookup;)V"
With the new version of the data binding library, you don't explicitly add the databinding dependency then apply it. All you need is dataBinding{enabled = true;} Other concerns: your target SDK version should probably not be 10 at this point.
Example:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
jcenter()
}
}
and
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.yourappname"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true;
}
}
dependencies {
//other dependencies
}
I don't recall if the neenbedankt gradle plugin is strictly necessary, but it's very useful for compile time annotation processing.

Categories

Resources