2017-11-28 8 views
0

のAndroid Studioのプロジェクト/ build.gradleで3.0データバインディング:ButterKnife、Kotlin:生成されませバインディングファイル

:アプリで

classpath 'com.android.tools.build:gradle:3.0.1' 

/build.gradle:

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' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-kapt' 
apply plugin: 'realm-android' 

def keystoreProperties = new Properties() 
keystoreProperties.load(new FileInputStream(rootProject.file("app/keystore.properties"))) 

android { 
    dataBinding { 
     enabled = true 
    } 
    compileSdkVersion 26 
    defaultConfig { 
     applicationId "com.myproject.android.customer" 
     minSdkVersion 15 
     targetSdkVersion 26 
     versionCode 1 
     versionName "0.1.1" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

     //multiDexEnabled true 
    } 
    signingConfigs { 
     release { 
      keyAlias keystoreProperties['KEY_ALIAS_RELEASE'] 
      keyPassword keystoreProperties['KEY_PASSWORD_RELEASE'] 
      storeFile file(keystoreProperties['STORE_FILE_RELEASE']) 
      storePassword keystoreProperties['STORE_PASSWORD_RELEASE'] 
     } 
    } 

    /*- exclude buildTypes = "debug" from build Variants 
    variantFilter { variant -> 
     if (variant.buildType.name.equals('debug')) { 
      variant.setIgnore(true); 
     } 
    }*/ 


    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 

      // sign settings 
      signingConfig signingConfigs.release 

      // config Fabrice (Beta of Crashlytics) 
      ext.betaDistributionReleaseNotes = defaultConfig.versionName + " " + name 
      ext.betaDistributionEmailsFilePath = "app/beta_distribution_emails.txt" 
     } 
     debug { 
      ext.alwaysUpdateBuildId = false // not need CrashLytics on debug mode 

     } 
    } 

} 

依存関係{ 実装ファイルツリー(dir: 'libs'、include:['* .jar'])

implementation('com.crashlytics.sdk.android:crashlytics:[email protected]') { transitive = true; } 

implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
implementation 'com.android.support:appcompat-v7:26.1.0' 
implementation 'com.android.support:design:26.1.0' 
implementation 'com.android.support:recyclerview-v7:26.1.0' 
// must use pdf-viewer:1.6.0 
implementation 'com.github.barteksc:android-pdf-viewer:1.6.0' 
//implementation 'com.github.markomilos:paginate:0.5.1' 
implementation 'com.google.android.gms:play-services-location:11.4.2' 
implementation 'com.google.android.gms:play-services-maps:11.4.2' 
implementation "com.github.bumptech.glide:glide:$GLIDE_VERSION" 
implementation "com.jakewharton:butterknife:$BUTTER_KNIFE_VERSION" 
implementation 'com.jayway.jsonpath:json-path:2.4.0' 
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0' 
implementation 'com.squareup.retrofit2:converter-gson:2.1.0' 
implementation 'com.squareup.retrofit2:retrofit:2.3.0' 
implementation 'commons-io:commons-io:2.5' 
implementation 'io.realm:android-adapters:2.0.0' 
implementation 'org.greenrobot:eventbus:3.0.0' 
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$KOTLIN_VERSION" 

implementation project(':common') 

kapt "com.github.bumptech.glide:compiler:$GLIDE_VERSION" 
kapt "com.jakewharton:butterknife-compiler:$BUTTER_KNIFE_VERSION" 

// test dependencies 
testImplementation 'junit:junit:4.12' 
androidTestImplementation 'com.android.support.test:runner:1.0.1' 
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 

}

repositories { 
    mavenCentral() 
    maven { url 'https://maven.fabric.io/public' } 
} 

私のレイアウトの名前がある:offer_item.xml。ファイル名をバインドするので、結果として

は次のとおりです。OfferItemBinding

ここに私のRecyclerViewAdapter:

import com.myproject.android.customer.databinding.OfferItemBinding; 

    public OfferSortAdapter.OfferViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
      LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 
      OfferItemBinding binding = OfferItemBinding.inflate(inflater, parent, false); 
      return new OfferViewHolder(binding.getRoot(), this); 
     } 

ここでのxmlレイアウト:

<?xml version="1.0" encoding="utf-8"?> 
<layout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 

    <data> 

     <variable 
      name="offer" 
      type="com.myproject.android.customer.api.model.Offer" /> 
    </data> 
</layout> 

ファイルOfferItemBindingは生成されませんでした。

そして、私はエラーを取得:私は私のポストを更新

D:\dev\MyProject\app\src\main\java\com\myproject\android\customer\ui\adapter\OfferSortAdapter.java:29: 

error: package com.myproject.android.customer.databinding does not exist 
    import com.myproject.android.customer.databinding.OfferItemBinding; 
+0

アプリレベルのbuild.gradleください –

+0

を – Alex

+0

会社kotlinのバターナイフの代わりに合成。それはkotlinからのものであり、バターナイフよりも優れています。 [link](https://kotlinlang.org/docs/tutorials/android-plugin.html) –

答えて

1

try this in build.gradle

dependencies { 
     //for butterknife 
     implementation 'com.jakewharton:butterknife:8.8.1' 
     kapt 'com.jakewharton:butterknife-compiler:8.8.1' 

     implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 
     kapt "com.android.databinding:compiler:2.3.3" 
    } 


apply plugin: 'kotlin-android-extensions' 
apply plugin: 'kotlin-kapt' 
apply plugin: 'kotlin-android' 

kapt { 
    generateStubs = true 
} 

in your RecylerviewAdpater

public class MyViewHolder extends RecyclerView.ViewHolder { 
private final ItemBinding binding; 

public MyViewHolder(ItemBinding binding) { 
    super(binding.getRoot()); 
    this.binding = binding; 
} 

public void bind(Item item) { 
    binding.setItem(item); 
    binding.executePendingBindings(); 
} 
} 

Now, my adapter can create and bind using Android Data Binding:

public MyViewHolder onCreateViewHolder(ViewGroup parent, 
             int viewType) { 
    LayoutInflater layoutInflater = 
     LayoutInflater.from(parent.getContext()); 
    ItemBinding itemBinding = 
     ItemBinding.inflate(layoutInflater, parent, false); 
    return new MyViewHolder(itemBinding); 
} 

public void onBindViewHolder(MyViewHolder holder, int position) { 
    Item item = getItemForPosition(position); 
    holder.bind(item); 
} 
+0

助けてください。同じエラー。 – Alex

+0

あなたはkotlinとバターナイフの両方を使っていますか? –

+0

はい、butternknifeとkotlinを使用しています – Alex

関連する問題