Skip to content Skip to sidebar Skip to footer

Cannot Set the Value of Read-only Property 'outputfile' for Apkvariantoutputimpl_decorated

More than one year has passed since last update.

posted at

updated at

僕たちはいつまでこんな楽しいAndroid Studio設定をし続けるのか? Android Studio three.x時代の設定不足解消メモ

概要

本稿はAndroid Studio 2.x世代に開発したアプリをAndroid Studio 3.ten世代でビルドするときに遭遇した事象と対策のメモです。

  • Androidアプリを開発していると、頻繁に開発環境のアップデートがあります
  • 開発環境をアップデートすると頻繁に古いプロジェクトがビルドできなくなります
    (昔は通用したのに、今は通用しなくなる)

ビルドの成否に影響を及ぼす要素

  • Android Studioのバージョン
  • Gradleのバージョン
  • Android Pluginのバージョン
  • SDK Build Toolsのバージョン
  • Android Plugin Repositoryの場所
  • Default Library Repositoryの場所
  • Android SDK Toolsのバージョン
  • Android Support Libraryのバージョン
  • JDKバージョン

これらが絶妙に調合されていないとビルドは成功しません。これは(Androidかいわいに限った話でなく)宿命なのでその時代に応じて何とか乗り越えていく必要があります。

Android Studioのバージョン

Android Studioは 3系を対象にします
https://developer.android.com/studio/?hl=ja


【問題】Gradle versionAndroid Plugin VersionSDK Build Tools versionの組み合わせ問題

起こりがちなエラー

以下のメソッドがサポートされていませんエラー

                Error:Unsupported method: BaseConfig.getApplicationIdSuffix().                              
                Error:Unsupported method: GradleProject.getProjectDirectory().                              

古いGradleにしてくださいエラー

                Gradle sync failed: Gradle version 2.2 is required. Current version is 4.10.one. If using the gradle wrapper, endeavour editing the distributionUrl in ...                              
                Gradle sync failed: No signature of method: coffee.util.ArrayList.all() is applicable for argument types: ... Possible solutions: any(), tail(), terminal(), last(), add(coffee.lang.Object), add(java.lang.Object) (10 s 345 ms)                              

原因

古いプロジェクトを開いた等で、Gradle versionAndroid Plugin VersionSDK Build Tools versionの組み合わせがあっていない。

解決策

以下に正しい組み合わせが出ているので、それを確認する

https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
image.png

2019年1月現在だと以下が最新の組み合わせ

設定 バージョン
Gradle version 4.10.1
Android Plugin 3.3.0
Build Tools 28.0.3

Build Toolsのリリースノートはこちら

Android StudioのProject ConstructionGradle versionAndroid Plugin Versionを設定する

File>Project Construction>Projection と選択してGradle version4.10.aneAndroid Plugin Version3.3.0と入力する。
image.png

build.gradle (Module:app) で buildToolsVersionを設定する

bulid.gradle(appレベル)で buildToolsVersion28.0.3とする。

build.gradle(app)

                                      apply                    plugin:                    'com.android.application'                    android                    {                    compileSdkVersion                    xix                    buildToolsVersion                    "28.0.iii"                    ...                                  

これで、Gradle versionAndroid Plugin VersionSDK Build Tools versionが正しい組み合わせとなった。

Tips
たとえ、以下のように Gradle versionを古くするように提案されてもbuild.gradlebuildToolsVersionを最新にあわせればたいてい問題は消える。

                Gradle sync failed: Gradle version 2.ii is required. Current version is 4.ten.1.                              

解説・参考サイト

https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
https://developer.android.com/studio/releases/build-tools#notes


【問題】Android Plugin Versionをあげようとしたらプラグインがリポジトリからみつからない

起こりがちなエラー

gradle依存ライブラリがみつかりませんエラー

                Gradle sync failed: Could not notice com.android.tools.build:gradle:3.0. Searched in the following locations: - https://jcenter.bintray.com/com/android/tools/build/gradle/iii.0/gradle-three.0.pom - https://jcenter.bintray.com/com/android/tools/build/gradle/iii.0/gradle-3.0.jar                              

原因

Android Pluginは 3.0.0以降、jcenterではなく、google独自のmavenリポジトリから配信されているため

解決策その1

File>Project Structure>Projection と選択してAndroid Plugin Repository'https://maven.google.com' を設定する

以下のようにAndroid Plugin Repositoryに jcenter,'https://maven.google.com'のように両方設定しておいてOK

image.png

設定 バージョン
Gradle version 4.10.1
Android Plugin 3.3.0
Build Tools 28.0.iii
Android Plugin Repository jcenter,'https://maven.google.com'
Default Library Repository jcenter

解決案その2

Android Studioでなく、コード側に設定してもOK。ルート(プロジェクトレベル)のbuild.gradlehttps://maven.google.comを追加するが、https://maven.google.comと書かなくてもgoogle()と書けば同じ意味になるので、そのようにする。

build.gradle(プロジェクトレベル)

                                      buildscript                    {                    repositories                    {                    jcenter                    ()                    google                    ()                    }                    dependencies                    {                    classpath                    'com.android.tools.build:gradle:3.3.0'                    }                    }                    allprojects                    {                    repositories                    {                    jcenter                    ()                    google                    ()                    }                    }                                  

解説・参考サイト


【問題】Gradle versionを上げたら、今までは問題なかった記述がエラー扱いされる

起こりがちなエラーや警告

minSdkは AndroidManifest.xml じゃなくて build.gradleに書いてねエラー

                Mistake: The minSdk version should non be declared in the android manifest file. You tin move the version from the manifest to the defaultConfig in the build.gradle file. Remove minSdkVersion and sync project                              

targetSdkは AndroidManifest.xml じゃなくて build.gradleに書いてね警告

                Alert: The targetSdk version should not be alleged in the android manifest file. Yous can motility the version from the manifest to the defaultConfig in the build.gradle file. Move targetSdkVersion to build file and sync project                              

原因

Gradle 3.0.0以降、記述ルールが大きめの変更がはいっているため
(https://programmer.android.com/studio/build/gradle-plugin-iii-0-0-migration)

解決策

以下の記述が AndroidManifest.xmlにあったら、それを消して build.gradleに以降する。

AndroidManifest.xml

                                      <uses-sdk                    android:minSdkVersion=                    "19"                    android:targetSdkVersion=                    "19"                    />                    ...                                  

↓↓↓

build.gradle(app)

                                      use                    plugin:                    'com.android.application'                    android                    {                    compileSdkVersion                    26                    buildToolsVersion                    "28.0.three"                    defaultConfig                    {                    applicationId                    "com.example.sony.smarteyeglass.extension.helloworld"                    minSdkVersion                    nineteen                    targetSdkVersion                    26                    }                                  

(Android向けのIDEの主流がEclipseからAndroid Studioに変わったとき、AndroidManifest.xmlに記述していた内容の一部がbuild.gradleに移行したが、minSdkVersionは、ついにエラー扱いになってしまったということ。)

解説・参考サイト


【問題】APKがビルドできない

起こりがちなエラーや警告

                Gradle sync failed: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=Chief, fullName=release, filters=[], versionCode=1, versionName=ane.0.0}} of blazon com.android.build.gradle.internal.api.ApkVariantOutputImpl.                              

原因

Androidプラグインが3.0.0以降になった影響のため

https://programmer.android.com/studio/build/gradle-plugin-3-0-0-migration
(新しいプラグインでは、Variant API を使用してバリアント出力を操作することができません)

解決策

  • 修正前bulid.gradle

build.gradle(before)

                                      applicationVariants                    .                    all                    {                    variant                    ->                    if                    (                    variant                    .                    buildType                    .                    name                    .                    equals                    (                    "release"                    ))                    {                    variant                    .                    outputs                    .                    each                    {                    output                    ->                    if                    (                    output                    .                    outputFile                    !=                    zero                    &&                    output                    .                    outputFile                    .                    name                    .                    endsWith                    (                    '.apk'                    ))                    {                    output                    .                    outputFile                    =                    new                    File                    (                    output                    .                    outputFile                    .                    parent                    ,                    "HelloWorld.apk"                    )                    }                    }                    }                    }                                  
  • 修正後bulid.gradle

build.gradle(after)

                                      android                    .                    applicationVariants                    .                    all                    {                    variant                    ->                    variant                    .                    outputs                    .                    all                    {                    outputFileName                    =                    "${variant.name}-${variant.versionName}.apk"                    }                    }                                  

解説・参考サイト


【問題】無効なJDKを参照している

起こりがちなエラー

                Gradle sync failed: Could not determine coffee version from 'ix.0.1'. (one s 411 ms)                              
                The supplied javaHome seems to be invalid. I cannot find the java executable.                              

原因

無効(Android Studioおよびツールにとって)なJDKが指定されている

解決策

Android Studioのメニューから File>Projection Structure>SDK Locationを選択して、Use embedded JDK(recommended)をチェックして有効にする。
image.png


【問題】Android SDK Tools が古い

起こりがちなエラー・警告

                Android SDK Tools Version 24.0.ii or after is required.                              

原因

Android SDK Toolsには、Android Emulator や ProGuard など、基本的なツールが含まれているが、これが現在の開発環境に対して古い。

解決案

最新の Android SDK Toolsをインストールする。
- SDK Manager経由でインストールする
- Android Studio上からインストールする

解説・参考サイト

https://developer.android.com/studio/releases/sdk-tools
https://developer.android.com/studio/intro/update#sdk-manager

まとめ

  • 古い開発環境で作ったAndroidアプリプロジェクトを最新の開発環境に取り込もうとするときに発生しがちな事象と対策をまとめました。
  • こういった作業はいつの時代にも必ず発生するコストなのであらかじめ見積もっておく(+つきあう覚悟)のが良いようにおもいます。
  • 1つずつ地道に対応してビルドが通ったときはとてもスッキリします。

Why not register and get more than from Qiita?

  1. Nosotros will deliver manufactures that friction match you

    By following users and tags, you can take hold of upwards information on technical fields that yous are interested in equally a whole

  2. you can read useful information later efficiently

    By "stocking" the articles you lot like, you lot can search right away

Sign upLogin

chamberlainthavestoon.blogspot.com

Source: https://qiita.com/riversun/items/78353cb2b3a8c7aa97a5

Post a Comment for "Cannot Set the Value of Read-only Property 'outputfile' for Apkvariantoutputimpl_decorated"