• ButterKnife使用


    这个快速注解插件非常好用,但是要注意,本人在用的时候用它去onclick的时候报空指针异常下面说说怎么用。

    1.在file里面选择

    搞定之后,还需要在APP下的build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'com.neenbedankt.android-apt' //加这一句
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.example.administrator.myapplication0022"
            minSdkVersion 15
            targetSdkVersion 25
            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(include: ['*.jar'], dir: 'libs')
        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:25.2.0'
        testCompile 'junit:junit:4.12'
        compile 'com.jakewharton:butterknife:8.0.1'
        apt 'com.jakewharton:butterknife-compiler:8.0.1'//加这一句
     }

    ,另外在项目的build.gradle里面

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.0'
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'//加这一句
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

    这些都做完之后就可以快乐的使用注解和快速生成点击监听了,但有时候会generate会不出现butterknife这个插件选项,需要在File -> settings -> Plugins  -> Browse repositories -> 搜索ButterKnife,安装完成后restart,重启studio就可以用了

  • 相关阅读:
    Redmine-java-api使用
    Junit4 基于 custom Rule retry
    Extentreports在安卓中的应用
    uiautomator 2.0 自定义testrunner使用
    uiautomator 启动原理
    uiautomator 自定义注解的应用
    uiautomator 原理 (UiAutomation、UiAutomatorBridge、QueryController)
    uiautomator 自定义testrunner使用和启动原理
    HeadFirstPython-文件与异常
    HeadFirstPython-初识python
  • 原文地址:https://www.cnblogs.com/laoyimou/p/6651885.html
Copyright © 2020-2023  润新知