LoginSignup
0
1

More than 1 year has passed since last update.

【Android】ビルドバリアントを設定してコンポーザブルのプレビューを実行したときに発生したエラーのまとめ

Last updated at Posted at 2023-01-08

発生したエラーのまとめ

最初に発生したエラーは、releaseでビルドしたことが原因だった。

Error: The apk for your currently selected variant cannot be signed. Please specify a signing configuration for this variant (free-release).

最後に発生したエラーはapplicationIdSuffix ".debug"を設定したままプレビューを実行したことが原因だった。

Execution failed for task ':app:processFreeDebugGoogleServices'.
> No matching client found for package name 'com.takagimeow.example.debug'

エラー発生時の状況

build.gradlebuildTypesproductFlavorsを使ってビルドバリアントを設定した。

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
    }
    debug {
        applicationIdSuffix ".debug"
        debuggable true
    }
}

flavorDimensions "plan"

productFlavors {
    paid {
        dimension "plan"
    }
    free {
        dimension "plan"
    }
}

同期後、次のビルドバリアントが作成された。

  • freeDebug
  • paidDebug
  • freeRelease
  • paidRelease

名称未設定のデザイン (23).png

無料アプリと有料アプリで、同じクラスでも処理を分けるようにするため、2つのディレクトリを作成した。
そして、それぞれに同じ名前のコンポーザブルファイルを作成した。

- src
    - freeRelease
        - com.takagimeow.example
            - feature
                - home
                    - HomeScreen.kt
    - paidRelease
        - com.takagimeow.example
            - feature
                - home
                    - HomeScreen.kt

Active Build VariantとしてfreeReleaseを選択した。
そして、コンポーザブルのプレビューを確認するために、**Run 'HomeScreenPreview'**を実行した。

名称未設定のデザイン (25).png

ビルドバリアントを設定する前には出現しなかったウィンドウが表示された。

名称未設定のデザイン (24).png

ウィンドウにはエラー内容が書かれていた。

Error: The apk for your currently selected variant cannot be signed. Please specify a signing configuration for this variant (free-release).

調べてみると、BuildTypeがreleaseの場合は正しく署名する必要があるらしい。
つまり、今まではBuildTypeがdebugの状態でプレビューを実行していたということだ。

解決した手順

freeReleaseディレクトリの名前を、freeに変更した。
paidReleaseディレクトリの名前を、paidに変更した。

新たに、空のdebugディレクトリを作成した。

- src
    - debug
    - free
        - com.takagimeow.example
            - feature
                - home
                    - HomeScreen.kt
    - paid
        - com.takagimeow.example
            - feature
                - home
                    - HomeScreen.kt

Sync Project with Gradle Filesを実行後、Active Build VariantをfreeDebugにした状態で、Run 'HomeScreenPreview' を実行した。

Buildにはエラーが表示された。

Execution failed for task ':app:processFreeDebugGoogleServices'.
> No matching client found for package name 'com.takagimeow.example.debug'

buildTypesdebugで、applicationIdSuffix ".debug"を設定したのが原因だった。
なので、コメントアウトする。

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.debug
    }
    debug {
        // applicationIdSuffix ".debug"
        debuggable true
    }
}

もう一度Sync Project with Gradle Filesを実行後、Active Build VariantをfreeDebugにした状態で、Run 'HomeScreenPreview' を実行した。

結果エラーは全て消え、エミュレーターが起動しコンポーザブルが表示された。

追記

applicationIdSuffix ".debug"を設定したときにエラーが発生した本当の原因は、Firebaseを使用するために生成したgoogle-services.jsonに設定されたpackage_nameには.debugが付与されていないことが本当の原因だった。

Execution failed for task ':app:processFreeDebugGoogleServices'.
> No matching client found for package name 'com.takagimeow.example.debug'

google-services.jsonをFirebase Consoleで作成した際に登録したパッケージ名はcom.takagimeow.exampleだった。

ところが、applicationIdSuffix ".debug"を設定したことによりアプリケーションのパッケージ名はcom.takagimeow.example.debugに変更されるので、google-services.jsonに設定した内容と一致しないためエラーが発生した。

なので、Firebaseを使わない人には発生しないエラーだと思うので、安心してapplicationIdSuffix ".debug"を使用してほしい。

参考にした記事

0
1
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
1