8.4.0 なのに「updating the version of com.google.android.gms to 8.3.0」

このように怒られ,

Execution failed for task ':app:processDebugGoogleServices'. Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 8.3.0.

build.gradle を見ると「8.4.0」

apply plugin: 'com.google.gms.google-services'
...
dependencies {
  ...
  compile 'com.google.android.gms:play-services-gcm:8.4.0'
  ...
}

こんな答えだと.

android - Version conflict updating to 8.4.0 - Stack Overflow

...
dependencies {
  ...
  compile 'com.google.android.gms:play-services-gcm:8.4.0'
  ...
}

// 最終行にもってくる
apply plugin: 'com.google.gms.google-services'

 

まとめ

build.gradle (project-top)

...
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
        classpath 'com.google.gms:google-services:2.0.0-alpha3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
...

build.gradle (app-module)

...
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    ...
    compile 'com.google.android.gms:play-services:8.4.0'
    ...
}
apply plugin: 'com.google.gms.google-services'

おつかれさまでした.

google-services_build_gradle_at_master_·_googlesamples_google-services

google-services/build.gradle


Android Studio 2.0 で「set ANDROID_DAILY_OVERRIDE environment variable to "*****"」

ビルド時に謎のエラーメッセージ.

Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to "*****"

環境変数「ANDROID_DAILY_OVERRIDE」とか初めて見た.

トップレベルの build.gradle をとりあえず(非推奨だが)書き換えるといける.

dependencies {
    classpath 'com.android.tools.build:gradle:+'
    ....
}

固定で書く場合, 今の最新バージョンはいくつか.

Maven_Repository__com_android_tools_build_»_gradle

Maven Repository: com.android.tools.build » gradle

いや, alpha だし, これか.

com_android_tools_build_gradle

com.android.tools.build.gradle

New_Build_System_-_Android_Tools_Project_Site

New Build System - Android Tools Project Site

エラーメッセージどおりに, OSX なら以下の後, プロジェクトをクリーンして, Android Studio再起動.

launchctl setenv ANDROID_DAILY_OVERRIDE *****

しかし, 引き続き新たなエラーメッセージが...

8.4.0 なのに「updating the version of com.google.android.gms to 8.3.0」


Android で よくある正規表現を使えるやつ

そもそもは Linkify のWEBリンクがなんだかな, と思い.

device-2011-08-23-153643

使えそうなよくある正規表現がいくつか用意されていたのですな.

public static final Pattern WEB_URL = Pattern.compile(
    "((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
  + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
  + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
  + "(?:" + DOMAIN_NAME + ")"
  + "(?:\\:\\d{1,5})?)"
  + "(\\/(?:(?:[" + GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"
  + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?"
  + "(?:\\b|$)");
public static final Pattern PHONE
  = Pattern.compile(                
      "(\\+[0-9]+[\\- \\.]*)?"      
    + "(\\([0-9]+\\)[\\- \\.]*)?"   
    + "([0-9][0-9\\- \\.]+[0-9])"); 
public static final Pattern EMAIL_ADDRESS
  = Pattern.compile(
    "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
    "\\@" +
    "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
    "(" +
        "\\." +
        "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
     ")+"
  );

platform_frameworks_base/Patterns.java

すぐにそのまま使おう.


if (Patterns.WEB_URL.matcher(text).find()) {
  // do something
}

「厳格なのか?」でフィルターをつける場合.

// A match filter that only accepts odd numbers.
MatchFilter oddFilter = new MatchFilter() {
    public final boolean acceptMatch(CharSequence s, int start, int end) {
        int n = Character.digit(s.charAt(end-1), 10);
        return (n & 1) == 1;
    }
};

// Match all digits in the pattern but restrict links to only odd
// numbers using the filter.
Pattern pattern = Pattern.compile("[0-9]+");
Linkify.addLinks(text, pattern, "http://...", oddFilter, null);

Android Text Links Using Linkify