【質問です】こんなの表示されて消えないのですがこのスマホはコインマイニングに利用されているのでしょうか?

通知バーから、こんなダイアログがこんなダイアログが表示されてるのですが、英語が分かりません。

Google翻訳で翻訳してみます。

LineaGenuine

This device is uncertified and it didn't pass the validation.
In order to avoid malicious usage of the device's resources, LOSCoins will be mined on this device.

LineaGenuine

このデバイスは認証されておらず、検証に合格しませんでした。
デバイスのリソースの悪意のある使用を避けるため、LOSCoinはこのデバイスでマイニングされます。

先日、Googleが Uncertified な端末は排除するとかアナウンスしてましたよね。

端末の登録

...

...

え!

誰が勝手にマイニングしとんねんな!

「No」や「Cancel」を押してみると

え!

怖くなってググります。

LineaGenuine (both 15.1 and 14.1)
Our new tool allows you to feel more comfortable knowing whether you’re running a certified build. In case the device is caught running an uncertified OS, this tool will warn the user and some measures will be taken in order to guarantee you the device’s resources aren’t being misused.
If you want to disable the persistent notification, run this command from a root shell (such as adb root / recovery or terminal app) setprop persist.lineage.nofool true and reboot the device

Changelog 17 - Building Blockchains, Genuine Guarantee, and Lucky Lock – LineageOS – LineageOS Android Distribution

どうやら、エイプリルフールネタのようです。

setprop persist.lineage.nofool true && stop && start

LOSCoins on my device? Yes/No : LineageOS

ネタで良かったです。

ちなみに、Googleに認証されている端末かどうかを確認するには、「PlayStore」アプリから、

「設定」-「端末の認証」

です。

今年もよろしくおねがいします。


あなたの build.gradle バージョン記述、きもいです。

きもいですよ。

こう書いていたり、


minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion

こう書いてたり、


dependencies {
  implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
  implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
  implementation "com.android.support:design:$rootProject.supportLibraryVersion"

「変数を使ってまとめました!」とか言ってるけど。

きもいですよ。

そもそも、定義の位置がヘボいのですよ。

 

書いてたのは私です。

以下のように書いてました。

root/build.gradle


ext {

  minSdkVersion = 24
  targetSdkVersion = 27
  compileSdkVersion = 27
  buildToolsVersion = '27.0.2'

  supportLibraryVersion = '27.1.0'
  firebaseVersion = '11.8.0'

}

これのせいで、「${rootProject.firebaseVersion」とか「rootProject.ext.***」とかダラダラ書く羽目になるようです。

stackoverflow も今やゴミのだらけでどれが正しいのか分かりづらいです。

 

神はこのように書いていた。

root/build.gradle


buildscript {

  ext.buildConfig = [
      'compileSdk': 27,
      'minSdk': 24,
      'targetSdk': 27
  ]

  ext.versions = [
      'supportLibrary': '27.1.0',
      'kotlin': '1.2.30',
      'okhttp': '3.10.0',
      'retrofit': '2.3.0',
      'kotshi': '1.0.1',
      'dagger': '2.15',
  ]

ブロック buildscript {} 内に map ですっきり記述しています。

module/build.gradle


android {

  compileSdkVersion buildConfig.compileSdk

  defaultConfig {

    minSdkVersion buildConfig.minSdk
    targetSdkVersion buildConfig.targetSdk

    versionCode buildConfig.versionCode
    versionName buildConfig.versionName

  }
}

// ....

dependencies {

  implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}"
  implementation "com.android.support:appcompat-v7:${versions.supportLibrary}"
  implementation "com.android.support:support-v4:${versions.supportLibrary}"
  implementation "com.android.support:design:${versions.supportLibrary}"

  implementation "com.google.firebase:firebase-core:${versions.firebase}"
  implementation "com.google.firebase:firebase-auth:${versions.firebase}"

定形なテンプレートとして使えます。

参照する際は、「rootProject」とか「ext」の単語は不要です。

 

関連の以下も必須だろうと思います。

サポートライブラリのバージョンを揃える

👉 【Gradle Version Catalog】libs.versions.toml キー名の形式 camelCase vs kebab-case hatena-bookmark


イベントハンドラとラムダ

おさらい


val printHelloWorld = {
   println("Hello, world!")
}

printHelloWorld()
//printHelloWorld.invoke()

これで以下が出力される。

Hello, world!

同様に引数を渡す。


val printGreeting = { word: String, name: String ->
   println("$word, $name")
}

printGreeting("おはよう", "太郎")
printGreeting.invoke("こんにちは", "次郎")

おはよう, 太郎
こんにちは, 次郎

これまでのコールバック

inferface を使ったコールバックは kotlin では以下のように書けます。


interface CallBackListener {
    fun onHoge(foo: String, bar: Int)
}

// caller
var callback: CallBackListener? = null
callback?.onHoge("foo", 100)

// callee
val callback = object : CallBackListener {
    override fun onHoge(foo: String, bar: Int) {
        print("$foo : $bar")
    }
}

これを typealias で。


typealias CallBackListener = (foo: String, bar: Int) -> Unit

// caller
var callback: CallBackListener? = null
callback?.invoke("foo", 100)

// callee
val callback = { foo, bar ->
    print("$foo : $bar")
}

【Kotlin】 TypeAliasで関数リテラルに名前を付ける - Qiita

イベントハンドラ

例えば、RecyclerView でそれぞれのアイテムのViewHolder内のある要素のクリックイベントを拾いたい時、Activity(View)までが遠いですよね。

Activity(View)
↓↑
RecyclerViewAdapter
↓↑
ViewHolder

少しでも、コールバック記述をシンプルにして見通し良くしておきたいものです。

ここで Type Alias を使います。

typealias EventHandler = (T) -> Unit

java - Kotlin: Use a lambda in place of a functional interface? - Stack Overflow

1. ViewHolder にハンドラー記述。クラスの外。

ItemViewHolder:


internal typealias ItemHandler = (Item) -> Unit

それを拡張して、ハンドラークラスを作ります。
invoke を override します。

ShareItemHandler:


internal class ShareItemHandler(
  private val activity: Activity
) : ItemHandler {

  override fun invoke(item: Item) {
    IntentBuilder.from(activity)
        .setType("text/plain")
        .setChooserTitle("Share ${item.name} to ?")
        .setText("${$item.name} ${item.address}")
        .startChooser()
  }
}

ClipboardCopyItemHandler:


internal class ClipboardCopyItemHandler(
  private val context: Context
) : ItemHandler {

  override fun invoke(item: Item) {
    val clipboard = context.systemService<ClipboardManager>()
    clipboard.primaryClip = ClipData.newPlainText(item.name, item.address)
  }
}

2. Activity で そのインスタンスを生成して
RecyclerAdapter経由でViewHolder内にセットしていきます。

以下関係部分のみ抜粋。

MainActivity:


val onCopy = ClipboardCopyItemHandler(this)
val onShare = ShareItemHandler(this)

// ...

val layoutManager = LinearLayoutManager(this)
recyclerView.layoutManager = layoutManager
val adapter = ItemAdapter(layoutInflater, onCopy, onShare)
recyclerView.adapter = adapter

ItemAdapter:


internal class ItemAdapter(
  private val inflater: LayoutInflater,
  private val onCopy: (Item) -> Unit,
  private val onShare: (Item) -> Unit
) : RecyclerView.Adapter<ItemViewHolder>() {

  // ...

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
    val view = inflater.inflate(R.layout.item, parent, false)
      return ItemViewHolder(view, onCopy, onShare)
    }

ItemViewHolder:



internal typealias ItemHandler = (Item) -> Unit // ***

internal class ItemViewHolder(
  private val root: View,
  private val onCopy: ItemHandler
  private val onShare: ItemHandler,
) : ViewHolder(root), OnClickListener, OnMenuItemClickListener {

  // ...  

  override fun onClick(view: View) = when(view.id) {
    R.id.copy -> onCopy(item!!)
    R.id.share -> onShare(item!!)
    else -> throw IllegalArgumentException("Unknown menu item: $menuItem")
  }

なんだか素晴らしいですね。

RecyclerView利用時のテンプレートとして。


【Android Studio】ビルド環境を安定した最新バージョンにする

様々なものに依存したAndroidアプリ開発環境は最新なものにしたいものです。

「開発環境」と一言で言ったりしますが、Android Studio は様々な「バージョン」で構成されています。

今回は、Android Studio上で、その中でもいわゆる「ビルド環境」的な部分について設定してみます。

 

Android Studio Gradle Plugin

Android Studio を標準的に、当たりまえに使うにはGradleを利用するこのプラグインが必須です。

先述のGradleのバージョンはこのプラグインに強く依存しています、

Android Plugin for Gradle Release Notes | Android Studio

よって、Gradle のバージョンアップの際にはここを確認するとよいです。

パッケージ名が「com.android.tools.build:gradle」となり、現在はGoogleのリポジトリで管理されています。

Google's Maven Repository

設定変更は、Project/build.gradle です。


buildscript {

    repositories {
        google()
    }

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

 

Gradle

Android Studioで使う際、推奨されているのは Gradle Wrapper なスタイルです。

Gradle Distributions

以下ファイルで最新版の設定をしましょう。

gradle/wrapper/gradle-wrapper-properties


distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip

 

Kotlin Gradle Plugin / Kotlin

もうKotlinでいいですよね。

StackOverFlowでも時代遅れなコードばかりで段階的なバージョン各過程を含めたコードばかりでその確認に四苦八苦して時間を費やすことになりますがKotlinなキーワードで検索すればその手間を避けることができます。

最近は公式系ドキュメントでもKotlinが優先されており、Kotlin化はさらに加速していくのは間違いありません。

Saving Files | Android Developers

KotlinをGradleで利用するには、このプラグインを利用することになります。

Android Studio – Migration from Maven Central to JCenter | Blog @Bintray

java - Android buildscript repositories: jcenter VS mavencentral - Stack Overflow

最新版の確認は、jetbrainsが管理しているMVNRepositoryで確認することができます。


Maven Repository: org.jetbrains.kotlin » kotlin-gradle-plugin

設定変更は同じ、Project/build.gradle です。


buildscript {
    ext.kotlin_version = '1.2.20'

    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

 

まとめ

以上をまとめておきます。

Project/build.gradle


buildscript {

    // kotlin / kotlin gradle plugin version
    ext.kotlin_version = '1.2.20'

    repositories {
        google()
        jcenter()
    }

    dependencies {

      // android studio gradle plugin
      // https://dl.google.com/dl/android/maven2/index.html
      classpath 'com.android.tools.build:gradle:3.0.1'

      // kotlin / kotlin gradle plugin
      // https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

gradle/wrapper/gradle-wrapper-properties


distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

# https://services.gradle.org/distributions/
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip

オープンソースを利用したプラットフォームや開発環境のバージョンの調整は

「stable最新」

にしておくことが幸せになることの王道です。

関連各所の利益や手間を考慮したしがらみが悩みのタネですよね。

Gradle Dependency バージョンのチェックを「最新」に更新する方法


Amazon vs Google の排除合戦に Apple が参入した?

ネットの中立性があやしくなってきていますが。

米、「ネットの中立性」撤廃 コンテンツの扱い格差容認 (写真=AP) :日本経済新聞

Net Neutrality - Bloomberg

で、最近のニュース。

GoogleはEcho Show向けにAmazonが用意したYouTubeアプリがGoogleの利用規約に違反しているとして、Echo ShowでYouTubeを使えないようにしました。その直後、AmazonはGoogle系列のスマートホーム企業Nestの一部製品をAmazonで販売停止にして対抗します。

AmazonとGoogleのバトルが激化 ユーザー不在の締め出し合戦へ - ITmedia PC USER

そんなことを考えながら、

ADBをアップデートして少しビビる、今日。

ビルドツールを更新すると、OS X上でADBが動作しなくなる

Updating to build tools 27.0.2 breaks ADB on OS X : androiddev


$ cd $ANDROID_SDK_ROOT
$ rm -r platform-tools/
$ curl https://dl.google.com/android/repository/platform-tools_r26.0.2-darwin.zip -o platform-tools_r26.0.2-darwin.zip
$ unzip platform-tools_r26.0.2-darwin.zip

iPhone の Apple をGoogleの敵と単純に考えてしまってはいけませんね。

すいません。