質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Groovy

Groovyは、Java用のオブジェクト指向型プログラミング言語です。PythonやRuby、Perl、そしてSmalltalkに似た特徴を有する動的な言語です。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

Q&A

解決済

1回答

504閲覧

AndroidのSecrets-Gradle-Pluginが正常に動かない

himoooooono

総合スコア1

Groovy

Groovyは、Java用のオブジェクト指向型プログラミング言語です。PythonやRuby、Perl、そしてSmalltalkに似た特徴を有する動的な言語です。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

0グッド

0クリップ

投稿2023/12/14 02:35

実現したいこと

Secrets-Gradle-Pluginを使ってAPIキーをGitに載せないようにしたい

前提

AndroidでGoogleMapsPlatformのMaps for Android SDKを使ったアプリを制作中
Googleのガイド(https://developers.google.com/maps/documentation/android-sdk/config?hl=ja)
に沿って進めていたのですが、アプリの実行時にAPIキーが読み込めない旨のエラーが発生して躓きました。
調べたところ似たような問題を聞いている人はいたのですが(https://stackoverflow.com/questions/75719652/secrets-gradle-plugin-not-working-with-android-manifest)
試しても変化がなかったため質問板立てました

発生している問題・エラーメッセージ

Attribute meta-data#com.google.android.geo.API_KEY@value at AndroidManifest.xml:29:13-44 requires a placeholder substitution but no value for <MAPS_API_KEY> is provided.

該当のソースコード

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

Groovy

1buildscript { 2 dependencies { 3 classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" 4 } 5} 6plugins { 7 id 'com.android.application' version '8.0.2' apply false 8 id 'com.android.library' version '8.0.2' apply false 9 id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false 10}

アプリモジュールレベルのbuild.gradle

Groovy

1plugins { 2 id 'com.android.application' 3 id 'com.google.gms.google-services' version '4.4.0' apply false 4 id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false 5} 6 7~~~以下省略~~~

試したこと

プラグインの順番の確認
プロジェクトの再ビルド
Gradleの同期

補足情報(FW/ツールのバージョンなど)

IDE:Android Studio Flamingo | 2022.2.1 Patch 2
Android Gradle Plugin Version:8.0.2
Gradle Version:8.0
Compile Sdk Version:33
Target SDK Version:33
Min SDK Version:26

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

質問と同じ環境・状況・エラーでは無いかもしれませんが、質問のリンク先の方法でプロジェクトを生成してみました。
build すると

Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed with multiple errors, see logs

と AndroidManifext.xml の android:value="${MAPS_API_KEY}" の行のエラーとなりました。

local.properties に MAPS_API_KEY=~ を書いた所ビルド出来てマップが表示されたため、 local.properties には空の宣言 MAPS_API_KEY= だけを残し、 secrets.properties に中身のある MAPS_API_KEY=~ を書いてみると、同じくビルドもマップ表示も出来ました。

gradle secrets plugin が現状どうなっているのか分かりませんが、 "KEY を secrets.properties に書いて使用する" という点ではこのような方法で出来ましたということで。

AndroidManifest.xml

xml

1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools"> 4 5 <application 6 android:allowBackup="true" 7 android:dataExtractionRules="@xml/data_extraction_rules" 8 android:fullBackupContent="@xml/backup_rules" 9 android:icon="@mipmap/ic_launcher" 10 android:label="@string/app_name" 11 android:roundIcon="@mipmap/ic_launcher_round" 12 android:supportsRtl="true" 13 android:theme="@style/Theme.Q_7aqy6y5ccp594t" 14 tools:targetApi="31"> 15 16 <activity 17 android:name=".MainActivity" 18 android:exported="true"> 19 <intent-filter> 20 <action android:name="android.intent.action.MAIN" /> 21 22 <category android:name="android.intent.category.LAUNCHER" /> 23 </intent-filter> 24 </activity> 25 26 <meta-data 27 android:name="com.google.android.geo.API_KEY" 28 android:value="${MAPS_API_KEY}"/> 29 30 </application> 31 32</manifest>

build.gradle(Project: q_7aqy6y5ccp594t)

groovy

1// Top-level build file where you can add configuration options common to all sub-projects/modules. 2buildscript { 3 dependencies { 4 classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" 5 } 6} 7plugins { 8 id 'com.android.application' version '8.2.0' apply false 9}

build.gradle(Module :app)

groovy

1plugins { 2 id 'com.android.application' 3 id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' 4} 5 6android { 7 namespace 'com.teratail.q_7aqy6y5ccp594t' 8 compileSdk 34 9 10 defaultConfig { 11 applicationId "com.teratail.q_7aqy6y5ccp594t" 12 minSdk 29 13 targetSdk 34 14 versionCode 1 15 versionName "1.0" 16 17 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 } 19 20 buildTypes { 21 release { 22 minifyEnabled false 23 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 } 25 } 26 compileOptions { 27 sourceCompatibility JavaVersion.VERSION_1_8 28 targetCompatibility JavaVersion.VERSION_1_8 29 } 30} 31 32dependencies { 33 34 implementation 'androidx.appcompat:appcompat:1.6.1' 35 implementation 'com.google.android.material:material:1.10.0' 36 implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 37 implementation 'com.google.android.gms:play-services-maps:18.2.0' 38 testImplementation 'junit:junit:4.13.2' 39 androidTestImplementation 'androidx.test.ext:junit:1.1.5' 40 androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 41}

local.properties

## This file is automatically generated by Android Studio. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file should *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. sdk.dir=C\:\\Users\\Jimbe\\AppData\\Local\\Android\\Sdk MAPS_API_KEY=

secrets.properties

MAPS_API_KEY=AIz … TIw

投稿2023/12/14 10:41

jimbe

総合スコア12659

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問