zoukankan      html  css  js  c++  java
  • Android Studio配置Dagger2 以及butterknife

    一、配置butterknife

    在build.gradle(Module)文件中的dependencies模块添加:

     dependencies {
        // add butterknife
        compile 'com.jakewharton:butterknife:6.1.0'
    }

    然后点击右上角Sync Now运行成功后可以在External Libraries中查看到butterknife的jar包。

    二、配置Dagger2

    1、在build.gradle(Module)文件中的dependencies模块添加:

     dependencies {
        // add dagger2
        compile 'com.google.dagger:dagger:2.0'
        apt 'com.google.dagger:dagger-compiler:2.0'
    }

    然后点击Sync Now会发现运行失败,这是因为还没有添加android-apt插件的引用。

    2、build.gradle(Module)文件顶部添加android-apt插件应用:

    apply plugin: 'android-apt'

    3、build.gradle(Project)文件的模块添加:

     dependencies {
            //add android-apt
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        }

    然后点击Sync Now运行成功,配置完成。下面给出整个build.gradle文件代码:

    build.gradle(Module)文件:

    apply plugin: 'com.android.application'
    apply plugin: 'android-apt'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "24.0.1"
    
        defaultConfig {
            applicationId "com.lz.www.ambts"
            minSdkVersion 15
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
        dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.4.0'
        compile 'com.android.support:design:23.4.0'
    
        // add dagger2
        compile 'com.google.dagger:dagger:2.0'
        apt 'com.google.dagger:dagger-compiler:2.0'
    
        // add butterknife
        compile 'com.jakewharton:butterknife:6.1.0'
    
    }

    build.gradle(Project)文件:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.1.0'
    
            //add android-apt
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    
            // 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
    }
  • 相关阅读:
    Linux并发与同步专题 (1)原子操作和内存屏障
    Linux并发与同步专题
    功耗案例分析:周期性底电流抬高问题分析和解决
    Android OpenGL 基础入门
    使用Codeblock搭建Windows下Objec-c学习环境
    Muduo 多线程模型对比
    NPTL 线程同步方式
    C++ 封装互斥对象
    Java 常用字符串操作总结
    Android 开发有用代码积累
  • 原文地址:https://www.cnblogs.com/kavilee/p/5718777.html
Copyright © 2011-2022 走看看