Cannot make Android databinding plugin work - android

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.

Related

Lambdas broken with gradle version 3.2.1

after i updated gradle version from 3.2.0 to version 3.2.1
all my lambda expressions are broken:
error: cannot find symbol method metafactory(Lookup,String,MethodType,MethodType,MethodHandle,MethodType)
my module-level build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "xyz.test.lambdatest"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
app-level build.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// 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
}
can anyone tell me why it works with gradle 3.2.0 but not with gradle 3.2.1?

Android Studio :: Gradle Scripts Error 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'
}
}
}

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'
}

Error:(19, 0) Gradle DSL method not found: 'android()' not solved

I have the problem:
Error:(19, 0) Gradle DSL method not found: 'android()'
-The project 'x' may be using a version of gradle thet does not contais the method
Open gradle wrapper file
-The build file may be missing a gradle plugin
Apply gradle plugin
build.gradle:
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()
}
}
android {
buildToolsVersion '23.0.0'
}
dependencies {
}
app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
compileOptions {
encoding "UTF-8"
}
defaultConfig {
applicationId "es.albertoramos.pfcalbertoramos"
minSdkVersion 15
targetSdkVersion 22
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:22.2.1'
}
How fix this problem?
Delete:
android {
buildToolsVersion '23.0.0'
}
dependencies {
}
from your top-level build.gradle.

Robospock and gradle build variants?

I'm using Robospock to perform unit testing and mocking with gradle. This worked great until I added gradle build variants to the mix.
My android build.gradle file:
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "0.0.1"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
uat {
packageName "com.acme.dev"
}
stage {
packageName "com.acme.staging"
}
prod {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.mcxiaoke.volley:library:1.0.4'
}
My robospock build.gradle file:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
classpath 'org.robospock:robospock-plugin:0.4.0'
}
}
repositories {
mavenCentral()
}
apply plugin: 'groovy'
dependencies {
compile "org.codehaus.groovy:groovy-all:1.8.6"
compile 'org.robospock:robospock:0.4.4'
compile 'cglib:cglib-nodep:2.2'
compile 'org.objenesis:objenesis:1.3'
}
project.ext {
robospock = ":Mothership" // project to test
}
apply plugin: 'robospock'
The Android gradle plug-in offers me build variant tasks such as assembleProd, assembleProdDebug, assembleStageDebugTest. Can I pass something to Robospocl in my build.gradle so that it can participate in the build variants?
Currently when I execute ./gradlew robospok, it cannot find the classes defined in com.acme.dev or com.acme.staging

Categories

Resources