Android studio中升級Gradle到3.x問題解決筆記

我算運氣不錯,只碰到了幾個問題,記下來才能避免以後又要東找西找solution囉~ =)

  1. app scope的gradle裡面要加上”flavorDimensions”
flavorDimensions "xxxflavor"
productFlavors {
        ProductionSigned {
            signingConfig android.signingConfigs.release_xxCompany
            dimension "xxxflavor"
        }
}

紅色兩個地方要加!意思就是至少要一個flavorDimensions,然後以後每一個product flavor裡面都要指定一個dimension才可以喔!

2. 我用到了指定apk名字的部份,這也要修改,

以前是:

variant.outputs.each { output ->
def apkName = variant.flavorName + “_” + buildType.name + “_”+variant.versionName + “_” + variant.versionCode + “.apk”;
output.outputFile = new File(output.outputFile.parent, apkName);
}

後來要改成:

variant.outputs.all {
    def apkName = variant.flavorName + "_" + buildType.name + "_" +
            variant.versionName + "_" + variant.versionCode + ".apk"
    outputFileName = apkName
}

我遇見了這兩個問題,提供已經驗證ok過的solution給有需要的朋友參考囉~希望你們可以早點解決這一些類似的問題喔! ^___^

一些相關參考:

  1. http://www.jianshu.com/p/47bf8941c0ac
  2. http://www.jianshu.com/p/9af06314e036

 

 

Android API Level Info

The info below is pretty useful, so I attached the pic here, the original source and the related link are listed as well!

螢幕快照 2017-12-04 上午9.08.44

The credit: https://stackoverflow.com/questions/3993924/get-android-api-level-of-phone-currently-running-my-application and the author is : birryree

2017.11.25-26 北五團十年11月份團集會

2017.11.25-26 「荒野協會北五團入團集會」
這兩天真的霹靂無敵趕,星期六一大早先參加小豆的運動會表演,一結束就馬上全家飛奔到淡水參加荒野的北五團十年入團集會活動!

兩天一夜的行程有著傳承,有著對於大自然環境的承諾,有著夥伴們互相扶持的善念,互相幫助的感動,我們這一個團體,真的散播著正向的能量,為環境努力付出的毅力,以及願意持續播種在大家心靈對於環境珍惜與感恩的態度。

這一切感動著我,也敦促著我,盡一份自我的心力來影響更多的朋友們,一同為著下一代留下更健康的生活環境,以及知足惜福的生活態度,將荒野的傳承,使命,以及精神,永續下去,幫助大自然萬物,都能和平相處,相知相惜!

一同努力吧!為這兩天一夜這麼有意義的旅程,留下一個最有溫度的註記!好愛大家~!👩‍👩‍👧‍👦❤️👨‍👩‍👧‍👦

2017.11.25-26 「荒野北五團十年。入團」

荷蘭兔在『何兆豐數位藝文中心』外的留影,她對小貝殼很有興趣呢! =)

IMG_6733

大家在聆聽『何兆豐數位藝文中心』內的導覽介紹。而荷蘭兔和彩虹馬很配合的在畫畫呢~好乖巧! =)

IMG_6737

 

晚餐吃飯的時間,鯊齒龍在欣賞著自己的介紹卡,彷彿和妹妹在介紹著鯊齒龍的特別之處! ^__^IMG_6747

晚上我們拿到了入團的領巾,這是一份傳承,希望將保護環境的毅力與決心,傳承給下一代們! =)IMG_6754

鯊齒龍從今天晚上(2017.11.25)晚上開始,正式的加入了北五團小蟻的行列!恭喜你!!我們一同努力保護地球! ^________^IMG_6760

由自然物做成的『秋之門廉』!這是鯊齒龍的創意結晶喔! ^_^IMG_6773IMG_6785IMG_6793

荷蘭兔也做了自己的『秋之門簾』,好開心呢! ^__^IMG_6799IMG_6802

這是『風之谷』家族的愛護地球宣言卡! =)IMG_6803IMG_6804IMG_6805IMG_6806IMG_6807IMG_6810IMG_6818IMG_6819IMG_6828

 

讓我們荒野北五團一同努力!創造永續美好的自然環境!一同加油! ^____^IMG_6835IMG_6838

使用Retrofit有一個一般人不太知道但是卻很重要的地方要注意!

如果你的Retrofit使用了OKHttp3,一定要注意這一個例外的可能性!

IllegalArgumentException in Headers$Builder.checkNameAndValue() for content-disposition filename response header

在okhttp的header裡面,如果你的value有非ascii的字元的話,你的程式是會crash的!這對很多人來說一定是一個坑,要多加小心喔! =)

  1. https://github.com/square/okhttp/issues/891
  2. https://github.com/square/okhttp/issues/1998

Firebase Remote Config使用時要注意的地方

  1. https://stackoverflow.com/questions/37311582/firebase-remote-config-cant-read-any-values-but-fetch-is-successful
  2. https://stackoverflow.com/questions/37501124/firebaseremoteconfig-fetch-does-not-trigger-oncompletelistener-every-time

如果已經打了fetch但是都沒有任何callback會回來,此時要注意有一種可能是因為你的google play service的版本太舊了,因為在一開始的firebase sdk中有bug,因此會造成沒有任何callback回call的現象。

更新你的firebase sdk,也更新你的google play store,即可解決這類的問題。

Android TV 設定Recommendation Item的背景『大圖』

前提假設:

***假設你的Recommendation Service已經可以正常執行了!***

實作步驟如下:

  1. Check google 文件,發現需要在Notification builder裡面設定setExtras()
    extra的內容:
    https://developer.android.com/reference/android/app/Notification.html
    裡面要去設定『EXTRA_BACKGROUND_IMAGE_URI
    因此!關鍵就在於這一行:
    ======

    extras.putString(Notification.EXTRA_BACKGROUND_IMAGE_URI, Uri.parse(BACKGROUND_URI_PREFIX + video.vCode).toString());

    ======
    而這個『BACKGROUND_URI_PREFIX』,指的是我們要使用ContentProvider來給Android TV系統存取需要的圖片檔案,這也意味著,當我們要指定extra的時候,我們需要事先將那些圖片給下載存放好才行!
    ex:

    BACKGROUND_URI_PREFIX = "content://com.sample.abc.recommend/";

    而『com.sample.abc.recommend』就是content provider的Authority,需要在AndoridManifest.xml中先定義好喔!

    例如:

    <provider
       android:name=".service.RecommendationsService$RecommendationBackgroundContentProvider"
       android:authorities="com.sample.abc.recommend"
       android:exported="true" />
  2. 接下來是定義好我們需要的『RecommendationBackgroundContentProvider』
    因為上述講到的extras.putString內容中的『Notification.EXTRA_BACKGROUND_IMAGE_URI』會去拿URI,所以這一個URI就是去ContentProvider中去打『openFile』這一個method,透過這一個Method,若是成功拿到圖片檔案的話,就大功告成囉!
    例如:

    public static class RecommendationBackgroundContentProvider extends ContentProvider {
    
        @Override
        public boolean onCreate() {
            return true;
        }
    
        @Override
        public int delete(Uri uri, String selection, String[] selectionArgs) {
            return 0;
        }
    
        @Override
        public String getType(Uri uri) {
            return null;
        }
    
        @Override
        public Uri insert(Uri uri, ContentValues values) {
            return null;
        }
    
        @Override
        public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
            String sortOrder) {
            return null;
        }
    
        @Override
        public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
            return 0;
        }
    
        @Override
        /*
         * content provider serving files that are saved locally when recommendations are built
         */
        public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
            String backgroundId = uri.getLastPathSegment();
            File bitmapFile = getNotificationBackground(getContext(), backgroundId);
            return ParcelFileDescriptor.open(bitmapFile, ParcelFileDescriptor.MODE_READ_ONLY);
        }
    }
    
    private static File getNotificationBackground(Context context, String notificationId) {
        return new File(context.getCacheDir(), notificationId + ".png");
    }

以上,全部完成,最重要的精華和步驟說明全都附上了!希望對大家有很明顯的幫助喔! =)

相關連結:

Google IO 2017 Notes

Kotlin

  1. Kotlin和Java的比較:
    https://kotlinlang.org/docs/reference/comparison-to-java.html
  2. Kotlin介紹:
    https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/

Android Studio 3.0 Preview

  1. 介紹入口點:
    https://developer.android.com/studio/preview/index.html

舊版Gradle file要調整的部分

  1. Migrate to the New Plugin:
    https://developer.android.com/studio/preview/features/new-android-plugin-migration.html

Google推出的新產品

  1. 『Google Lens』
    https://www.bnext.com.tw/article/44536/google-announces-google-lens-and-updates-google-photos?utm_campaign=2591667&utm_source=SendPulse&utm_medium=push&utm_content=201705181

其他應該要注意的地方

================

Google’s Maven repository for Android libraries

The Android Support Library dependencies are now available from Google’s Maven repository at maven.google.com—instead of downloading from the Android SDK Manager.

This new distribution method simplifies Maven dependency management for those using continuous integration systems.

Two new libraries available today are: Architecture Components LibraryAndroid Instant App Library, and we have updated Support Library to 26.0.0-beta1*.

In the future we plan to distribute all Android libraries only through maven.google.com.

From now on, the latest versions of the following libraries are available only from Google’s Maven repo (new versions are not available in the SDK Manager):

  • Android Support Library
  • Constraint Layout Library
  • Android Test Support Library
  • Databinding Library

To start using Google’s Maven repository, follow these instructions to update your build dependencies.

================

Google’s Maven repository


The most recent versions of the following Android libraries are available from Google’s Maven repository:

To add them to your build, add maven.google.com to the Maven repositories in your module-level build.gradle file:

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

Then add the desired library to your dependencies block. For example, the appcompat library looks like this:

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
}

However, if you’re trying to use an older version of the above libraries and your dependency fails, then it’s not available in the Maven repository and you must instead get the library from the offline repository.

================

See which libraries are in the Maven repo

Maven SDK Manager
Constraint layout
constraint-layout-solver 1.0.2
constraint-layout 1.0.2
All previous versions
Databinding
library: 1.0-rc0 – 1.3.1
adapters: 1.0-rc0 – 1.3.1
All versions up to 1.3.1
Support Library
compat: 24.2.0 – 26.0.0-beta1
leanback: 21.0.0 – 26.0.0-beta1
recommendation: 23..1 – 26.0.0-beta1
vector drawable: 23.2.0 – 26.0.0-beta1
recyclerview: 21.0.0 – 26.0.0-beta1
preference-leanback-v17: 23.0.0 – 26.0.0-beta1
preference-v14: 23.0.0 -26.0.0-beta1
percent 22.2.0 – 26.0.0-beta1
support-media-compat: 24.2.0 – 26.0.0-beta1
cardview-v7: 21.0.0 – 26.0.0-beta1
wearable: 26.0.0-beta1
exifinterface: 25.1.0 – 26.0.0-beta1
support-annotations: 19.1.0 – 26.0.0-beta1
appcompat-v7: 18.0.0 – 26.0.0-beta1
palette-v7: 21.0.0 – 26.0.0-beta1
multidex-instrumentation: 1.0.0, 1.0.1
multidex: 1.0.0, 1.0.1
mediarouter-v7: 18.0.0 – 26.0.0-beta1
preference-v7: 23.0.0 – 26.0.0-beta1
support-dynamic-animation: 25.3.0, 25.3.1
support-fragment: 24.2.0 – 26.0.0-beta1
design: 22.2.0 – 26.0.0-beta1
transition versions: 24.2.0 – 26.0.0-beta1
customtabs : 23.0.0 – 26.0.0-beta1
support-core-ui: 24.2.0 – 26.0.0-beta1
gridlayout-v7: 13.0.0 – 26.0.0-beta1
animated-vector-drawable: 23.2.0 – 26.0.0-beta1
support-core-utils: 24.2.0 – 26.0.0-beta1
support-v13: 13.0.0 – 26.0.0-beta1
instantvideo: 26.0.0-beta1
support-v4: 13.0.0 – 26.0.0-beta1
All previous versions
Support Test
runner: 0.2 – 0.6-alpha
rules: 0.2 – 0.6-alpha
exposed-instrumentation-api-publish: 0.2 – 0.6-alpha
testing-support-lib: 0.1
All versions up to 0.6-alpha
Janktesthelper
janktesthelper-v23: 1.0.0, 1.0.1
All versions up to 1.0.1
UIAutomator
uiautomator-v18: 2.0.0 – 2.1.2
All versions up to 2.1.2
Espresso
espresso-core: 2.0 – 2.3-alpha
espresso-web: 2.2 – 2.3-alpha
espresso-intents: 2.1 – 2.3-alpha
espresso-contrib: 2.0 – 2.3-alpha
espresso-idling-resource: 2.0 – 2.3-alpha
All previous version
Instant Apps
instantapps: 1.0.0
volleycompat: 1.0.0
N/A
Gradle plugin
gradle plugin: 3.0.0-alpha1
All previous versions on JCenter
Architecture Components
android.arch: 1.0.0-alpha1
N/A
GMS Core
N/A
All previous versions on JCenter
FirebaseN/A All previous versions on JCenter

================

Google’s offline repository from SDK Manager

For older versions of the libraries listed above and other libraries from Google not listed above (such as Google Play services and Firebase), you must first download the offline Google Repository package from the SDK Manager.

Then you can add these libraries to your dependencies block as usual:

depedencies {
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.google.firebase:firebase-core:9.8.0'
}

The offline libraries are saved in android_sdk/extras/.

================

Dependency order


The order in which you list your dependencies indicates the priority for each: the first library is higher priority than the second, the second is higher priority than the third, and so on. This order is important in the event that resources are merged or manifest elements are merged into your app from the libraries.

For example, if your project declares the following:

  • Dependency on LIB_A and LIB_B (in that order)
  • And LIB_A depends on LIB_C and LIB_D (in that order)
  • And LIB_B also depends on LIB_C

Then, the flat dependency order will be as follows:

  1. LIB_A
  2. LIB_D
  3. LIB_B
  4. LIB_C

This ensures that both LIB_A and LIB_B can override LIB_C; and LIB_D is still higher priority than LIB_B because LIB_A (which depends on it) has higher priority than LIB_B.

For more information about how manifests from different project sources/dependencies are merged, see Merge Multiple Manifest Files.

================

View the dependency tree


Some direct dependencies may have dependencies of their own. These are called transitive dependencies. Rather than requiring you to manually declare each transitive dependency, Gradle automatically gathers and adds them for you. To visualize both the direct and transitive dependencies of your project, the Android plugin for Gradle provides a Gradle task that generates a dependency tree for each build variant and testing source set.

To generate this report, proceed as follows:

  1. Select View > Tool Windows > Gradle (or click Gradle in the tool windows bar).
  2. Expand AppName > Tasks > android and double-click androidDependencies.
  3. To view the report, select View > Tool Windows > Gradle Console.

The following sample report shows the dependency tree for the debug build variant, and includes the local library module dependency and remote dependency from the previous example.

Executing tasks: [androidDependencies]
:app:androidDependencies
debug
/**
 * Both the library module dependency and remote binary dependency are listed
 * with their transitive dependencies.
 */
+--- MyApp:mylibrary:unspecified
|    \--- com.android.support:appcompat-v7:25.3.1
|         +--- com.android.support:animated-vector-drawable:25.3.1
|         |    \--- com.android.support:support-vector-drawable:25.3.1
|         |         \--- com.android.support:support-v4:25.3.1
|         |              \--- LOCAL: internal_impl-25.3.1.jar
|         +--- com.android.support:support-v4:25.3.1
|         |    \--- LOCAL: internal_impl-25.3.1.jar
|         \--- com.android.support:support-vector-drawable:25.3.1
|              \--- com.android.support:support-v4:25.3.1
|                   \--- LOCAL: internal_impl-25.3.1.jar
\--- com.android.support:appcompat-v7:25.3.1
     +--- com.android.support:animated-vector-drawable:25.3.1
     |    \--- com.android.support:support-vector-drawable:25.3.1
     |         \--- com.android.support:support-v4:25.3.1
     |              \--- LOCAL: internal_impl-25.3.1.jar
     +--- com.android.support:support-v4:25.3.1
     |    \--- LOCAL: internal_impl-25.3.1.jar
     \--- com.android.support:support-vector-drawable:25.3.1
          \--- com.android.support:support-v4:25.3.1
               \--- LOCAL: internal_impl-25.3.1.jar
...

For more information about managing dependencies in Gradle, see Dependency Management Basics in the Gradle User Guide.

================