`
scarlettli
  • 浏览: 55326 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

android studio导入第三方工具

阅读更多
      前面两篇博客中说到了在项目中运用EventBus、Volley以及Debuglog,也许会有很多人在想,怎么样才能把这些工具用到自己的项目中来呢?其实非常简单,只需要在gradle文件中加上几句话就可以了。
      首先来看看整个工程的(project)gradle文件
     
buildscript {
    repositories {
        jcenter()
        //DebugLog
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        //DebugLog
        classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}


      这个文件中其实只加了两句话:
     
dependencies {
    classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
  }

     
buildscript {
  repositories {
    mavenCentral()
  }

      当然,就加这么两句肯定还是不够的,接下来我们来看看项目(module)中的gradle文件
     
apply plugin: 'com.android.application'
//DebugLog
apply plugin: 'com.jakewharton.hugo'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.li.scarlett.myapplication"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    //将EventBus导入自己的项目
    compile 'de.greenrobot:eventbus:2.4.0'
    //将Volley导入自己的项目
    compile 'dev.dworks.libs:volleyplus:+'

}

      这个文件中就将EventBus、Volley和DebugLog都导入自己的项目中了,其实也就只加了三句话,非常简单。导入项目中后就来看看我们的项目中是怎么使用的吧,EventBus及Volley在前面的博客中已经说到怎么去使用,这里就不多提了。DebugLog的使用是非常简单的,只需要在你想要打印log的方法前加上@Debuglog这句话就可以了,然后就可以在log日志中看来这个方法的使用情况,看下面的代码:
     
@DebugLog
    public void onEventMainThread(ResultBeen event) {

        this.tv_result.setText(event.getResponse());

    }

  

      好了,今天就介绍这么多,大家可以去自己的项目中试试啦!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics