技术--工具--Gradle
Gradle基础知识
Gradle构建java
步骤:
Compile--Jar--Document--Test--report
Gradle构建Android
Android Studio目录介绍:
.gradle目录:
Gradle增量支持,存储的位置信息
.idea目录:
store its module of project
build目录:
输出目录
Gradle目录:
wrapper.jar和wrapper.proptes
高级Android构建
最终项目:实现突破
参考:
Udaciiy--用Gradle构建java和Adnroid
Android常用库:
butterknife:
1 介绍:
简单来说:
减少findViewById、OnclickListerner等重复操作。
官方说法:
Field and method binding for Android views which uses annotation processing to generate boilerplate code for you.
使用注释的方法,自动生成引用代码来绑定字段和方法。
2 使用方法:
1 Gradle普通方式:
dependencies {
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
2 作为库引入方式:
参考github官方文档
3 出现问题:
问题1:
Onclick事件不起作用
解决办法:确保module的build.gradle中没有
apply plugin: 'android-apt'
logger
1 介绍:
简单介绍:
Log输出工具类
官方说法:
Simple, pretty and powerful logger for android
漂亮、好看、强大的Android输出工具
2 使用方法:
compile 'com.orhanobut:logger:1.15'
3 其他选择
timber,作者还在持续更新
retrofit
RxAndroid
RxBinding
1 介绍:
RxJava binding APIs for Android's UI widgets.
okhttp
1 介绍:
An HTTP+HTTP/2 client for Android and Java applications.
okio
1
A modern I/O API for Java
dagger
1
A fast dependency injector for Android and Java
SuperToasts
1
A library that extends the Android toast framework.
Toast弹窗
字体Calligraphy
1
Custom fonts in Android the easy way...
使用步骤:
1 添加依赖库:
dependencies {
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
}
2 Application中添加:
CalligraphyUtil.initFonts();
3 Activityz中添加:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyUtil.superContextBase(newBase));
}
4 自定义View中需要手动添加:
CalligraphyUtil.setTextViewStyle(context,textview);
5 在assets目录新建fonts目录,,
CalligraphyUtil源码:
public class CalligraphyUtil {
private static String path = "fonts/founder_black.ttf";
public static void initFonts() {
CalligraphyConfig.initDefault(
new CalligraphyConfig.Builder()
.setDefaultFontPath(path)
.setFontAttrId(R.attr.fontPath)
.addCustomViewWithSetTypeface(CustomViewWithTypefaceSupport.class)
.addCustomStyle(TextField.class, R.attr.textFieldStyle)
.build());
}
public static Context superContextBase(Context newBase) {
return CalligraphyContextWrapper.wrap(newBase);
}
public static void setTextViewStyle(Context context, TextView textView) {
CalligraphyUtils.applyFontToTextView(context, textView, path);
}
public static Typeface getTypeface(Context context) {
Typeface typeFace = Typeface.createFromAsset(context.getAssets(), path);
return typeFace;
}
}
uCrop
1
Image Cropping Library for Android
http://www.jianshu.com/p/669eda5dc5a4
第三方SDK:
Umeng
基础数据统计
Meiqia:
意见反馈
--待整理--
1 Butterknife:
Bind Android views and callbacks to fields and methods
插件android-butterknife-zelezny:
Android Studio plug-in for generating ButterKnife injections from selected layout XML.
2 Picasso:
A powerful image downloading and caching library for Android
首次使用Target被垃圾回收,不会掉的解决办法:
参考1
3 stetho
Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more
Stetho.initializeWithDefaults(context);
使用浏览器访问地址:chrome://inspect/
参考:http://stormzhang.com/android/2015/03/05/android-debug-use-chrome/
4 otto
Otto is an event bus designed to decouple different parts of your application while still allowing them to communicate efficiently.
5 RxAndroid
RxJava bindings for Android
RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
时间处理第三方库:
http://www.joda.org/joda-time/
http://www.date4j.net/
讲解1
分章讲解2
Airbnb:我们的安卓客户端是如何使用 RxJava 的
Google类似框架:agera
讲解网络使用
6 LeakCanary
内存泄露监测
7 EventBus
Android optimized event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality
8 otto
An enhanced Guava-based event bus with emphasis on Android support.
9 Rxbus:
http://hanhailong.com/2015/10/09/RxBus%E2%80%94%E9%80%9A%E8%BF%87RxJava%E6%9D%A5%E6%9B%BF%E6%8D%A2EventBus/
10 lombok:
Very spicy additions to the Java programming language
11 Dragger:
参考1
参考2
1###2 MVP架构:
参考文章
参考文章2
参考文章3:MVP在Android平台上的应用
参考项目AndroidMvpExample
参考项目Archi:
Repository that showcases 3 Android app architectures: "Standard Android", MVP and MVVM. The exact same app is built 3 times following the different patterns.
参考项目EffectiveAndroidUI:
Sample project created to show some of the best Android practices to work in the Android UI Layer. The UI layer of this project has been implemented using MVP or MVVM (without binding engine) to show how this patterns works. This project is used during the talk "EffectiveAndroidUI".
参考项目AndroidMvp
参考项目PhotoNoter
Material Design风格的开源照片笔记。(MVP+Dagger2+RxJava+Dex分包脚本+Dex异步加载)
好处:
代码简洁
解耦网络请求和View刷新
对从后台获取的数据进行处理后,交给View展示。如果API变动,只需修改逻辑,不需要修改View
13 Retrofit2(include OkHttp)
RxJava 与 Retrofit 结合的最佳实践
14 Android架构演化之路
Android架构规范
android-architecture
15 数据库:
Ormlite
Realm Java:
掘金文章1
Github
16 Apache Common IO:
IO操作工具类
APP框架搭建:
网络请求: Retrofit+OkHttp(retrofit rxjava)
图片处理: Picasso(imageloader)
Json解析: fastJson或者Gson
依赖注入: Dagger
数据库: Ormlite或者greenDao
聊天,XMPP;
动画,NineOldAndroids。
推送:Jpush
反馈:美洽
Im框架演变
多个app名称和包名打包
1 配置gradle,android{ }内添加如下代码:
productFlavors {
app_location {
applicationId "com.example.app1"
manifestPlaceholders = [
app_name:"有定位"
]
}
app_nolocation {
applicationId "com.example.app2"
manifestPlaceholders = [
app_name:"无定位"
]
}
}
2 配置AndroidManifest.xml:
在application标签中配置 android:label="${app_name}"
参考如下代码:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar"
android:icon="@mipmap/ic_launcher"
android:label="${app_name}"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
>
</application>
3 执行命令生成apk包:
针对某一个包名打包:
./gradlew assembleapp_location
打包所有:
./gradlew assemble
多渠道打包:
1 配置build.gradle
参考上面<多个app名称和包名打包>代码:
productFlavors {
app_location {
applicationId "com.example.app1"
manifestPlaceholders = [
app_name:"有定位",
UMENG_CHANNEL_VALUE:"定位"
]
}
app_nolocation {
applicationId "com.example.app2"
manifestPlaceholders = [
app_name:"无定位",
UMENG_CHANNEL_VALUE:"无定位"
]
}
}
2 配置AndroidManifest.xml
<meta-data
android:name="UMENG_APPKEY"
android:value="53152b656240b0a941143297a" />
<meta-data
android:name="UMENG_CHANNEL"
android:value="${UMENG_CHANNEL_VALUE}" />
3 执行命令生成apk包:
./gradlew assemble
生成jar包(必须是android library的Model):
1 在model的 build.gradle 中添加如下代码:
task makeJar(type: Copy) {
delete 'build/libs/mysdk.jar'
from('build/intermediates/bundles/release/')
into('build/libs/')
include('classes.jar')
rename ('classes.jar', 'mysdk.jar')
}
makeJar.dependsOn(build)
2 执行命令:
./gradlew makeJar
3 遇到问题:
执行 ./gradlew makeJar命令时,遇到报错:
-bash: ./gradlew: Permission denied
解决方法:
chmod +x gradlew