工具篇--Gradle引用

技術--工具--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.lxweimin.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.

參考1 |
參考2 |
參考3

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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容