Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

MainActivity_ is not abstract and does not override abstract method findViewById(int) in HasViews #2001

Description

@timurgilfanov

I try to compile sample project with Android Studio 3.0-preview1 and Support Library 26.0.0-beta1 but get an compile time error "MainActivity_ is not abstract and does not override abstract method findViewById(int) in HasViews"

AndroidAnnotations version:
4.3.0
Android compile SDK version:
android-O
Project build config:

buildscript {

    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

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

Module build config:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-O'
    buildToolsVersion "26.0.0-rc2"
    defaultConfig {
        applicationId "com.example.timurgilfanov.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.0-beta1'
    annotationProcessor 'org.androidannotations:androidannotations:4.3.0'
    compile 'org.androidannotations:androidannotations-api:4.3.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

Annotated code:

@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {}

Expected generated code:

public final class MainActivity_ extends MainActivity implements HasViews, OnViewChangedListener
{
...
    @Override
    public View findViewById(int id) {
        ...
    }
...
}

Actual generated code:

package com.example.timurgilfanov.myapplication;

import android.app.Activity;
import android.content.Context;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import org.androidannotations.api.builder.ActivityIntentBuilder;
import org.androidannotations.api.builder.PostActivityStarter;
import org.androidannotations.api.view.HasViews;
import org.androidannotations.api.view.OnViewChangedNotifier;

public final class MainActivity_  extends MainActivity implements HasViews
{
    private final OnViewChangedNotifier onViewChangedNotifier_ = new OnViewChangedNotifier();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        OnViewChangedNotifier previousNotifier = OnViewChangedNotifier.replaceNotifier(onViewChangedNotifier_);
        init_(savedInstanceState);
        super.onCreate(savedInstanceState);
        OnViewChangedNotifier.replaceNotifier(previousNotifier);
        setContentView(R.layout.activity_main);
    }

    private void init_(Bundle savedInstanceState) {
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        onViewChangedNotifier_.notifyViewChanged(this);
    }

    @Override
    public void setContentView(View view, LayoutParams params) {
        super.setContentView(view, params);
        onViewChangedNotifier_.notifyViewChanged(this);
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        onViewChangedNotifier_.notifyViewChanged(this);
    }

    public static MainActivity_.IntentBuilder_ intent(Context context) {
        return new MainActivity_.IntentBuilder_(context);
    }

    public static MainActivity_.IntentBuilder_ intent(android.app.Fragment fragment) {
        return new MainActivity_.IntentBuilder_(fragment);
    }

    public static MainActivity_.IntentBuilder_ intent(android.support.v4.app.Fragment supportFragment) {
        return new MainActivity_.IntentBuilder_(supportFragment);
    }

    public static class IntentBuilder_
        extends ActivityIntentBuilder<MainActivity_.IntentBuilder_>
    {
        private android.app.Fragment fragment_;
        private android.support.v4.app.Fragment fragmentSupport_;

        public IntentBuilder_(Context context) {
            super(context, MainActivity_.class);
        }

        public IntentBuilder_(android.app.Fragment fragment) {
            super(fragment.getActivity(), MainActivity_.class);
            fragment_ = fragment;
        }

        public IntentBuilder_(android.support.v4.app.Fragment fragment) {
            super(fragment.getActivity(), MainActivity_.class);
            fragmentSupport_ = fragment;
        }

        @Override
        public PostActivityStarter startForResult(int requestCode) {
            if (fragmentSupport_!= null) {
                fragmentSupport_.startActivityForResult(intent, requestCode);
            } else {
                if (fragment_!= null) {
                    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
                        fragment_.startActivityForResult(intent, requestCode, lastOptions);
                    } else {
                        fragment_.startActivityForResult(intent, requestCode);
                    }
                } else {
                    if (context instanceof Activity) {
                        Activity activity = ((Activity) context);
                        ActivityCompat.startActivityForResult(activity, intent, requestCode, lastOptions);
                    } else {
                        if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
                            context.startActivity(intent, lastOptions);
                        } else {
                            context.startActivity(intent);
                        }
                    }
                }
            }
            return new PostActivityStarter(context);
        }
    }
}

Stacktrace in case of AA crash:
MainActivity_ is not abstract and does not override abstract method findViewById(int) in HasViews

Activity

  1. dodgex commented on May 18, 2017

    @dodgex
    Member

    The Problem is that Google changed the signature of thier findViewById in Android O from View findViewById(int id) to something like <T extends View> T findViewById(int id) (not exactly sure how the new syntax looks, saw that yesterday in one of the I/O streams).

    And we have our org.androidannotations.api.view.HasViews interface that has this method with the old syntax and until Android O the implementation came from the Activity class. but with this change on thier side they broke our interface...

    looks like for now we unfortunately do not support Android O due to this change.

    @WonderCsabo any idea for a good fix?

  2. WonderCsabo commented on May 18, 2017

    @WonderCsabo
    Member

    I would suggest to generate the old, findViewById method, but unfortunately that would not compile, because both methods have the same erasure. The only solution i see is introducing a HasViews2 interface, and implement that if compileSdkVersion >= Android O .

  3. naixx commented on May 22, 2017

    @naixx
    Contributor

    @WonderCsabo Any update on the issue? Is it possible just to rename findViewById method?

  4. dodgex commented on May 26, 2017

    @dodgex
    Member

    A PR to adress this issue is up.

  5. WonderCsabo commented on Jun 7, 2017

    @WonderCsabo
    Member

    @naixx no, we cannot just rename the method, because the generated code actually rely on implementing it implicitly by Activity.

  6. phanminhthu commented on Jan 18, 2018

    @phanminhthu

    Gradle add: maven { url 'https://jitpack.io' }.

    buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        
    
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    
    }
    

    }

    allprojects {
    repositories {
    google()
    jcenter()
    maven { url 'https://jitpack.io' }
    }
    }

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

    AND:

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    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'

    //annotation
    compile 'org.androidannotations:androidannotations-api:4.3.1'
    annotationProcessor 'org.androidannotations:androidannotations:4.3.1'
    implementation 'com.jakewharton:butterknife:8.8.1'
    

    }

  7. tir38 commented on Jan 25, 2018

    @tir38

    @phanminhthu can you explain what you are adding there?

  8. MarcosiOSdev commented on Jan 25, 2018

    @MarcosiOSdev

    What is the solutions for "MainActivity_ is not abstract and does not override abstract method findViewById(int) in HasViews" ?????

  9. MarcosiOSdev commented on Jan 25, 2018

    @MarcosiOSdev

    I solved ...
    I putted on version 4.4.0 , and It has the method "findViewById(int) in HasViews"

  10. edilsonvilarinho commented on Apr 14, 2018

    @edilsonvilarinho

    @marcosjava nice !!!

  11. mjafartp commented on Oct 24, 2018

    @mjafartp

    I solved ...
    I putted on version 4.4.0 , and It has the method "findViewById(int) in HasViews"

    com.android.tools.build:gradle version ?

  12. edilsonvilarinho commented on Nov 1, 2018

    @edilsonvilarinho

    I solved ...
    I putted on version 4.4.0 , and It has the method "findViewById(int) in HasViews"

    com.android.tools.build:gradle version ?

    sim

  13. peiandsky commented on Nov 6, 2018

    @peiandsky

    I solved ...
    I putted on version 4.4.0 , and It has the method "findViewById(int) in HasViews"

    com.android.tools.build:gradle version ?

    sim

    classpath 'com.android.tools.build:gradle:2.3.1'
    Gradle 4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions