jess-anders / two-way-gridview

An Android GridView that can be configured to scroll horizontally or vertically
650 stars 261 forks source link

Fatal Lint error: onLayout #33

Open dlazerka opened 9 years ago

dlazerka commented 9 years ago

Hi Jess, I don't know how to use this library in my project, (copy-pasting the code doesn't feel right). So I tried to add a library module (using git submodule to keep it up-to-date). However, when I selected "Import existing Eclipse ADT or Gradle project as a module", it asked me for Eclipse installation location (I don't have any). So I decided to create a build.gradle file (anyway Android is going the Gradle way, whether we want it or not). I had hard time figuring out proper settings, but finally found that someone already did that: https://github.com/AppFellas/TwoWayGridViewGradle/blob/master/build.gradle So I created a build.gradle file (below), but there's one problem, it throws a fatal Lint error, along with some non-fatal. Here it is:

WrongCall: Using wrong draw/layout method
../../src/com/jess/ui/TwoWayAdapterView.java:758: Suspicious method call; should probably call "layout" rather than "onLayout"
 755            // Force one here to make sure that the state of the list matches
 756            // the state of the adapter.
 757            if (mDataChanged) {
 758                this.onLayout(false, getLeft(), getTop(), getRight(), getBottom());
 759            }
 760        } else {
Note: This issue has an associated quickfix operation in Android Studio/IntelliJ Fix 
Priority: 6 / 10
Category: Correctness
Severity: Fatal
Explanation: Using wrong draw/layout method.
Custom views typically need to call measure() on their children, not onMeasure. Ditto for onDraw, onLayout, etc.

To reproduce this, go to /lib, place the build.gradle there, and run gradle build. Gradle version is 2.3, though I doubt that matters.

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.2'
    }
}

apply plugin: 'com.android.library'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 22
    buildToolsVersion '22.0.1'
    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 22
        versionCode 1
        versionName '1.0'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
    // Worakaround for fatal Lint error
    // lintOptions {
    //  abortOnError false
    // }
}
anthony-bernardo commented 8 years ago

I got the same error,

I can't build apk...

Up !

imikm commented 8 years ago

i couldn't generate apk , what shall i do ? i hadn't this error on my simulator.

ArcherN9 commented 8 years ago

Similar error, unable to generate a signed APK for deployment. Error : Error:(758) Error: Suspicious method call in TwoWayAdapterView.java; should probably call "layout" rather than "onLayout" [WrongCall]

imikm commented 8 years ago

in TwoWayAdapterView .... i changed onLayout to layout .... also the "false" variable is redundant and the layout method just need get left ,right,top and bottom i generated apk with no error

ArcherN9 commented 8 years ago

@imikm I tried that. Building a development build is easy. The hard part is if you attempt to build a signed APK for Play Store release. It just won't work, will continue giving the error I posted above.