Plaid Source Reading Notes

Hujiawei Bujidao


     

Plaid Source Reading Notes


Plaid源码阅读笔记。

1.AndroidManifest文件中的activity-alias使用

<!-- use an alias in case we want to change the launch activity later without breaking
     homescreen shortcuts.  Note must be defined after the targetActivity -->
<activity-alias
    android:name=".Launcher"
    android:label="@string/app_name"
    android:targetActivity=".ui.HomeActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>

2.在application中配置meta-data

<!-- Glide configurations for image loading -->
<meta-data
    android:name="io.plaidapp.util.glide.GlideConfiguration"
    android:value="GlideModule" />
<meta-data
    android:name="com.bumptech.glide.integration.okhttp.OkHttpGlideModule"
    android:value="GlideModule" />

甚至可以在AndroidManifest文件中获取到在Gradle配置的数据,比如下面的配置不同的渠道

//AndroidManifest
<meta-data
    android:name="UMENG_CHANNEL"
    android:value="${UMENG_CHANNEL_VALUE}" />

//build.gradle
productFlavors {
    playStore {
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "playStore"]
    }
    miui {
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "miui"]
    }
    wandoujia {
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
    }
}

3.Gradle中buildConfigField的配置 通过在Gradle文件中配置的buildConfigField可以在自动生成的BuildConfig文件中获取到,可以给不同的buildType设置不同的值。

build.gralde中添加一些BuildConfig字段

defaultConfig {
    applicationId "io.awesome"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    buildConfigField "String", "DRIBBBLE_CLIENT_ID", "\"${dribbble_client_id}\""
    buildConfigField "String", "DRIBBBLE_CLIENT_SECRET", "\"${dribbble_client_secret}\""
    buildConfigField "String", "DRIBBBLE_CLIENT_ACCESS_TOKEN", "\"${dribbble_client_access_token}\""
}

对于其中引用的字段值可以放在gradle.properties中配置

# Dribbble API
dribbble_client_id = xxx
dribbble_client_secret = yyy
dribbble_client_access_token = zzz

待Gradle Sync之后在文件app/build/source/BuildConfig/Build Varients/package name/BuildConfig就会看到添加的字段

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "io.awesome";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
  // Fields from default config.
  public static final String DRIBBBLE_CLIENT_ACCESS_TOKEN = "xxx";
  public static final String DRIBBBLE_CLIENT_ID = "yyy";
  public static final String DRIBBBLE_CLIENT_SECRET = "zzz";
}

4.在Gradle中定义supportLibVersion做到supportlib的版本统一

ext {
    archivesBaseName = "plaid-${android.defaultConfig.versionName}"
    supportLibVersion = '23.1.0'
}

dependencies {
    compile "com.android.support:support-v4:${supportLibVersion}"
    compile "com.android.support:palette-v7:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:customtabs:${supportLibVersion}"
    ...
}
Hujiawei is a mobile developer Guangdong, China http://javayhu.me/ 本博客所有文章均为原创,请勿随意转载,如需转载请联系我 (hujiawei090807 AT gmail.com) 我在小专栏有个移动开发技术专栏,不定期分享移动开发的核心技术,总结移动开发的实战经验
所有文章皆为原创,内容制作精良,保证干货满满,欢迎订阅 (https://xiaozhuanlan.com/u/javayhu)
>>> 我最近在Android面试指南小专栏里面写了一篇稿子 [Android面试——算法面试心得] ,欢迎阅读!<<<
下面的二维码是我个人维护的微信公众号“潇涧技术专栏”,会不定期分享移动开发的核心技术,欢迎关注!