LoginSignup
0
2

More than 5 years have passed since last update.

gradle(AndroidStudio)備忘録

Posted at

背景

年末、GoogleからこれからはtargetSdkVersionは最新のAPIレベルで開発してねー的なことが来た。
https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html

2018年8月:新規アプリで、targetSdkVersionが26(Android Oreo)以降必須
2018年11月:既存アプリのアップデートで、targetSdkVersionが26(Android Oreo)以降必須
2019年以降: Android OSバージョンアップの後、1年以内に、新しいアプリとアプリのアップデートは、対応するAPIレベル以降にターゲットを指定することが義務づけられます。

ってことで早めにGradle 3.0に対応しないといけない

Gradle3.0移行

SDK BuildTool

app/build.gradle
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.3" 

    defaultConfig {
        targetSdkVersion 26
    }
    ・・・
}

Android Plugin for Gradle

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

Gradle

gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Product Flavor

Product Flavorの設定をする必要がある場合、Flavor Dimensionsの設定が必須となる。

Dependency

次期メジャーリリースで、compileprovidedapkは削除される

移行後 用途
implementation 依存関係をモジュール内部でのみ使用し、外部に公開しない場合
api 依存関係を外部に公開する場合
compileOnly providedの代わり
runtimeOnly apkの代わり

※ サードパーティ製のライブラリの場合、公式に移行について書いているものもあるため、要チェック

apkファイル命名

  • gradle 3.0からVariant API を使用してバリアント出力を操作できなくなった
  • ビルド中の簡単なファイル命名はできる

参考

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html?hl=ja
https://qiita.com/taki4227/items/e9473441a7b2fe00e1f3

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2