JakeWharton / butterknife

Bind Android views and callbacks to fields and methods.
http://jakewharton.github.io/butterknife/
Apache License 2.0
25.56k stars 4.6k forks source link

All bind view are null #463

Closed steadymoka closed 8 years ago

steadymoka commented 8 years ago
public class AccountFragment extends BaseFragment {

    @Bind( R.id.editText_email ) EditText editText_email;
    @Bind( R.id.editText_password ) EditText editText_password;
    @Bind( R.id.textView_contract ) TextView textView_contract;

    private Realm realm;

    @Override
    public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {

        View rootView = inflater.inflate( R.layout.fragment_sign_in, container, false );
        setRootView( rootView );
        ButterKnife.bind( this, rootView );

        init();
        refresh();
        return rootView;
    }
        ...
}

in ButterKnife 8.0.0 snap shot ButterKnife 7.0.1

editText_email / editText_password / textView_contract are null ,

my project in android studio compileSdkVersion 23 ( tried v22 ) multiDexEnabled true Application extended MultiDexApplication turn off proguard

and use rxAndroid, realm, kotlin

plz Help

error log :

D/ButterKnife: Looking up view binder for com.moka.earlybird.application.mvc.controller.account.AccountFragment
D/ButterKnife: Not found. Trying superclass com.moka.framework.controller.BaseFragment
D/ButterKnife: Not found. Trying superclass android.support.v4.app.Fragment
D/ButterKnife: MISS: Reached framework class. Abandoning search.
JakeWharton commented 8 years ago

Code generation isn't happening. Do you see the generated classes in your build folder? They should be named as *$$ViewBinder.java.

steadymoka commented 8 years ago

I can't find generated classes which is named as *$$ViewBinder.java in my build folder

2016-04-01 8 57 46
JakeWharton commented 8 years ago

That indicates you have misconfigured your build system. What version are you using? How is it setup in your build.gradle?

On Thu, Mar 31, 2016, 7:57 PM moka-a notifications@github.com wrote:

I can't find generated classes which is named as *$$ViewBinder.java in my build folder

— You are receiving this because you commented.

Reply to this email directly or view it on GitHub https://github.com/JakeWharton/butterknife/issues/463#issuecomment-204179647

steadymoka commented 8 years ago

my project build.gradle

ext.kotlin_version = '1.0.0'

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-rc1'   // I tried 1.5.0 but same problem 
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'
        classpath 'io.fabric.tools:gradle:1.21.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.0"
        classpath "io.realm:realm-gradle-plugin:0.88.2"
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "http://devrepo.kakao.com:8088/nexus/content/groups/public/" }
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    }
}

and app build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'

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

android {
    compileSdkVersion 23         // I tried compileSdkVersion 22,
    buildToolsVersion '23.0.2'   // buildToolsVersion 22.0.1, targetSdkVersion 22 but same problem

    defaultConfig {
        .....
        multiDexEnabled true
    }
    productFlavors {
        .....
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
//   I tried this option but same problem 
//    lintOptions {
//        disable 'InvalidPackage'
//    }
//    packagingOptions {
//        exclude 'META-INF/services/javax.annotation.processing.Processor'
//    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
     ...
     compile 'com.jakewharton:butterknife:7.0.1'
}
JakeWharton commented 8 years ago

Is ProGuard removing them? You're sure they're not showing up in the build/ dir anywhere? Try running find . -name '*$$ViewBinder.java' in your project directory.

steadymoka commented 8 years ago

they doesn't exist anywhere ..

2016-04-01 3 19 30 and I turn off proguard

but, when I try in another project, *$$ViewBinder.java are exist.

JakeWharton commented 8 years ago

Are you trying to bind views in Kotlin code?

steadymoka commented 8 years ago

No, I've tried to bind views in java code.

like this

public class AccountFragment extends BaseFragment {

    @Bind( R.id.editText_email ) EditText editText_email;
    @Bind( R.id.editText_password ) EditText editText_password;
    @Bind( R.id.textView_contract ) TextView textView_contract;

    private Realm realm;

    @Override
    public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {

        View rootView = inflater.inflate( R.layout.fragment_sign_in, container, false );
        setRootView( rootView );
        ButterKnife.bind( this, rootView );

        init();
        refresh();
        return rootView;
    }
        ...
}

so, when I try to bind VIew in Kotlin code by Kotterknife problem which is same abve is occured

JakeWharton commented 8 years ago

Not sure what to tell you then. If you can create a sample project which demonstrates the problem I'll have a look.

steadymoka commented 8 years ago

First, thank you for your comment, but i couldn't find what is problem. so I've changed all java code to kotlin. and i use koltin-extensions for view injection.

but i'm using ButterKnife another project useful. Thank you

JakeWharton commented 8 years ago

Ok. Well if you think of anything I'd be curious to know what it was.

oinegue commented 8 years ago

Same issue here after a fresh installation of Android Studio 2.0. Solved after finding the link to manual configuration to "Enable annotation processing". Maybe should it be made clearer on the website?

Thanks for the great library.

JakeWharton commented 8 years ago

If you are using Gradle those instructions are not needed.

On Mon, Apr 18, 2016 at 6:20 PM oinegue notifications@github.com wrote:

Same issue here after a fresh installation of Android Studio 2.0. Solved after finding the link to manual configuration http://jakewharton.github.io/butterknife/ide-idea.html to "Enable annotation processing". Maybe should it be made clearer on the website?

Thanks for the great library.

— You are receiving this because you modified the open/close state.

Reply to this email directly or view it on GitHub https://github.com/JakeWharton/butterknife/issues/463#issuecomment-211604832

croute commented 8 years ago

I have same problem.

Realm version is 1.0.0 (plugin) ButterKnife version is 8.0.0 Trying to bind views in Java code. and other settings are similar.

theGlenn commented 8 years ago

Hey @JakeWharton I started having the exact same problem than @moka-a a few minutes after I added Kotlin to my project. And I ended up turning my activities to kotlin too.

theGlenn commented 8 years ago

Alight I found the problem if you are using Kotlin+Java in your project but still want to use annotation processing in your Java classes replace apt with kapt. Check this link: https://kotlinlang.org/docs/reference/using-gradle.html#annotation-processing

steadymoka commented 8 years ago

I used kapt but didnt work I will check your link Thank you

bean-liu commented 7 years ago

You will need to add "apt 'com.jakewharton:butterknife-compiler:8.4.0'" to your app build.gradle

thevoiceless commented 7 years ago

Seconding @bean-liu, the github page says to use annotationProcessor but the jakewharton.github.io page says to use apt. The former does not work for me, the latter does.

Based on this SO post, it sounds like it's an issue with the instructions vs the version of the Android Gradle plugin that is used (although I'm using 2.2.2 and still saw the issue).

Update for October 2016: You probably don't need apt and the android-apt plugin anymore. Version 2.2 of the Android Gradle plugin has an annotationProcessor configuration that you should be using instead.

LenaYan commented 7 years ago

I met the same issue, after using apt instead of annotationProcessor it works fine.

pinkApple commented 7 years ago

@JakeWharton I met the same issue too , the realm causes this problem. it's not kotlin's problem. when I delete realm in my build.gradle, everything work well.

butterknife can't work together with realm.

lDuffy commented 7 years ago

Getting the same issue using a mixed java/kotlin project with realm, dagger2 and butterknife. realm using kotlin doesn't generate schema when 'com.neenbedankt.android-apt' plugin is applied for some reason. I was getting the following error when trying to access realm objects "MyObject is not part of the schema for this realm". Removing the android-apt plugin, corrected this error but build was failing with dagger compelation errors.
replacing annotationProcessor 'com.google.dagger:dagger-compiler:2.6' with kapt 'com.google.dagger:dagger-compiler:2.6' fixed dagger compilation issue but now butterknife views are always null. I tried replacing annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' with kapt 'com.jakewharton:butterknife-compiler:8.4.0' but was failing with the following error error: cannot find symbol import butterknife.Unbinder;

krokyze commented 7 years ago

Didn't know why but at one moment the same problem appeared. Changing annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' to kapt 'com.jakewharton:butterknife-compiler:8.5.1' solved the problem.

I'm using Kotlin.

ConorOD commented 7 years ago

apt 'com.jakewharton:butterknife-compiler:8.5.1'

Worked for me too. Using java.

Fideas commented 7 years ago

For mixed Java/Kotlin projects add the following lines to your module level build.gradle

apply plugin: 'kotlin-kapt'
...
dependencies {
    ....
    compile 'com.jakewharton:butterknife:8.5.1'
    kapt 'com.jakewharton:butterknife-compiler:8.5.1'
    ...
}
kapt {
    generateStubs = true
}
Mathbl commented 7 years ago

Am I the only one to notice that with kapt, it is often necessary to clean the project? Every now and then, after making changes to code (layout or activities, doesn't seem to matter), my app crashes with a null pointer because of a null view. A project cleaning always fixes it. Looks like it could be related to that: https://youtrack.jetbrains.com/issue/KT-10303 but it's supposed to be fixed.

guuilp commented 6 years ago

@Mathbl I'm facing this issue. Did you find a workaround?

Mathbl commented 6 years ago

@guuilp Sadly no. I had to give up on the idea of gradually switch to Kotlin for now. There were some issues like this one that I was encountering and couldn't fix. Having to ship fast wasn't not compatible with build that fails randomly.

guuilp commented 6 years ago

@Mathbl that's sad to hear. Unfortunately, half of my project is already in Kotlin, so rollback is not an option. If you see any news about this issue, please refer it here. I'll do the same.

guuilp commented 6 years ago

@Mathbl see this comment: https://github.com/JakeWharton/butterknife/issues/966#issuecomment-310580310

I've been building the project for almost 5 hours and no clean project needed until now.

2hamed commented 6 years ago

I have the same problem here with a mixed Java/Kotlin app. Strangely it's just one of my activities (MainActivity) that the ButterKnife classes are not generated for. The rest of the app is ok. Had to convert that one activity to kotlin to get it to work.

itsmanoharkumar commented 6 years ago

I simply removed the Kotlin from my project and it started working again.

Kharlos commented 5 years ago

ok so if I create a project java/kotlin butterknife doesn't work really?

JakeWharton commented 5 years ago

Works fine with kapt

On Sat, Oct 13, 2018, 7:41 PM Carlos <notifications@github.com wrote:

ok so if I create a project java/kotlin butterknife doesn't work really?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/463#issuecomment-429584134, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEaArkMjEjgEMhm_ilL33-0-X-zR1ks5uknoZgaJpZM4H8lTB .

Kharlos commented 5 years ago

Im using

implementation 'com.jakewharton:butterknife:9.0.0-rc1' kapt 'com.jakewharton:butterknife-compiler:9.0.0-rc1'

but it doesn't work, needs other config?

rohankandwal commented 5 years ago

I am using java + Kotlin configuration since I am slowly migrating.

kapt {
  generateStubs = true
}

dependencies {
....
// View Injection
  implementation "com.jakewharton:butterknife:$rootProject.ext.butterKnifeVersion"
  kapt "com.jakewharton:butterknife-compiler:$rootProject.ext.butterKnifeVersion"
... }

Above code removed null issues after changing some adding Kotlin support to the JAVA project.