Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use com.android.databinding in module(Android studio)?

I want create a library using com.android.databinding: dataBinder.

build.gradle for project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.android.databinding:dataBinder:1.0-rc4'


        // 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" }
        //gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8580
    }
}


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

build.gradle for module :

apply plugin: 'com.android.library'  // apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.1"
        multiDexEnabled true
        generatedDensities = []
    }
    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:23.2.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.android.support:support-v4:23.2.0'
 }

I change apply plugin: 'com.android.application' to apply plugin: 'com.android.library'.But when I changed the code to the following error occured.

Error this :

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources] :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preDebugAndroidTestBuild UP-TO-DATE :app:preDebugUnitTestBuild UP-TO-DATE :app:preReleaseBuild UP-TO-DATE :app:preReleaseUnitTestBuild UP-TO-DATE :app:prepareComAndroidDatabindingAdapters10Rc3Library UP-TO-DATE :app:prepareComAndroidDatabindingLibrary10Rc3Library UP-TO-DATE :app:prepareComAndroidSupportAnimatedVectorDrawable2320Library UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72320Library UP-TO-DATE :app:prepareComAndroidSupportCardviewV72320Library UP-TO-DATE :app:prepareComAndroidSupportDesign2320Library UP-TO-DATE :app:prepareComAndroidSupportMultidex101Library UP-TO-DATE :app:prepareComAndroidSupportPaletteV72320Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72320Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42320Library UP-TO-DATE :app:prepareComAndroidSupportSupportVectorDrawable2320Library UP-TO-DATE :app:prepareComGithubAfollestadMaterialDialogsCore0856Library UP-TO-DATE :app:prepareComGithubOrangegangstersSwipy122Library UP-TO-DATE :app:prepareComMakeramenRoundedimageview221Library UP-TO-DATE :app:prepareDeKeyboardsurferAndroidWidgetCrouton185Library UP-TO-DATE :app:prepareMeZhanghaiAndroidMaterialprogressbarLibrary114Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources :app:processDebugManifest :app:dataBindingLayoutsProcessDebugResources :app:processDebugResources D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\build\intermediates\res\merged\debug\values-fa\values-fa.xml Warning:(70) warning: string 'app_name' marked untranslatable but exists in locale 'fa' :app:dataBindingInfoClassProcessDebugResources :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugSources :app:prepareComAndroidSupportMultidexInstrumentation101Library UP-TO-DATE :app:prepareDebugAndroidTestDependencies :app:compileDebugAndroidTestAidl :app:compileDebugNdk UP-TO-DATE :app:compileLint :app:copyDebugLint UP-TO-DATE :app:compileDebugJavaWithJavac D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\activities\common\MoreInfoAppActivity.java Error:(9, 39) error: package com.xomorod.utility.databinding does not exist Error:(14, 3) error: cannot find symbol class ActivityMoreInfoAppBinding D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\activities\splash\SplashPresenterActivity.java Error:(13, 39) error: package com.xomorod.utility.databinding does not exist Error:(25, 12) error: cannot find symbol class ActivitySplashBinding D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\section\fontManager\CardFont.java Error:(16, 39) error: package com.xomorod.utility.databinding does not exist Error:(64, 9) error: cannot find symbol class CardFontBinding D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\section\language\CardLanguage.java Error:(16, 39) error: package com.xomorod.utility.databinding does not exist Error:(63, 9) error: cannot find symbol class CardLanguageBinding D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\section\market\CardApp.java Error:(15, 39) error: package com.xomorod.utility.databinding does not exist Error:(58, 9) error: cannot find symbol class CardAppBinding D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\section\themeManager\CardTheme.java Error:(16, 39) error: package com.xomorod.utility.databinding does not exist Error:(63, 9) error: cannot find symbol class CardThemeBinding D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\activities\common\AbstractMainActivity.java Error:(25, 15) error: attribute value must be constant Error:(28, 15) error: attribute value must be constant Error:(31, 15) error: attribute value must be constant D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\activities\common\MoreApplicationActivity.java Error:(25, 15) error: attribute value must be constant Error:(28, 15) error: attribute value must be constant D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\activities\common\SettingsActivity.java Error:(230, 19) error: attribute value must be constant Error:(301, 19) error: attribute value must be constant Error:(383, 19) error: attribute value must be constant D:\WorkSpace\Android\Java\Xomorod\Utility\src\app\src\main\java\com\xomorod\utility\section\market\MoreAppFragment.java > Error:(37, 15) error: attribute value must be constant Error:(40, 15) error: attribute value must be constant Error:(43, 15) error: attribute value must be constant Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Error:Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.Information:BUILD FAILED Information:Total time: 12.413 secs Information:24 errors Information:1 warning Information:See complete output in console

like image 930
Ahmad Aghazadeh Avatar asked Mar 09 '16 19:03

Ahmad Aghazadeh


1 Answers

Follow the guide here:

http://developer.android.com/tools/data-binding/guide.html

You must add dataBinding.enabled = true to the android section. You should also use android gradle plugin 1.5.0 or later.

You don't need the apply plugin: 'com.android.databinding' anymore either. Data binding is now included into the android gradle plugin.

like image 126
George Mount Avatar answered Sep 17 '22 20:09

George Mount