android studio导入第三方工具
16lz
2021-01-26
前面两篇博客中说到了在项目中运用EventBus、Volley以及Debuglog,也许会有很多人在想,怎么样才能把这些工具用到自己的项目中来呢?其实非常简单,只需要在gradle文件中加上几句话就可以了。
首先来看看整个工程的(project)gradle文件
这个文件中其实只加了两句话:
当然,就加这么两句肯定还是不够的,接下来我们来看看项目(module)中的gradle文件
这个文件中就将EventBus、Volley和DebugLog都导入自己的项目中了,其实也就只加了三句话,非常简单。导入项目中后就来看看我们的项目中是怎么使用的吧,EventBus及Volley在前面的博客中已经说到怎么去使用,这里就不多提了。DebugLog的使用是非常简单的,只需要在你想要打印log的方法前加上@Debuglog这句话就可以了,然后就可以在log日志中看来这个方法的使用情况,看下面的代码:
好了,今天就介绍这么多,大家可以去自己的项目中试试啦!
首先来看看整个工程的(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());
}
好了,今天就介绍这么多,大家可以去自己的项目中试试啦!
更多相关文章
- Android(安卓)adb不是内部或外部命令 (转)
- Android常用开源项目库
- 移植ffmpeg到android_1
- android 支持的资源类型及其存放的目录
- Android:封装一个通用PopupWindow
- Github上100个经典开源Java项目 值得阅读学习
- Android(安卓)!No Launcher activity found!错误
- android初学之路【安卓入门二】
- Android实现文件下载