はじめに
AndroidStudio3に変更してjenkinsでビルドした時に出たエラーについて、対応をメモします。
エラーメッセージ
「Could not find com.android.tools.build:gradle:3.0.0-alpha3」
ローカル環境でStudioでビルドすると問題なかったのですが、gradlewコマンドで実行するとエラーが出ます。
原因
もともとはライブラリ系はjcenterからダウンロードしていましたが、GoogleI/O2017以降に一部がmavenに変更されたようです。
そのため、mavenからダウンロードが必要なライブラリがある場合にエラーになっていたようです。
改善
プロジェクトbuildファイルへmavenリポジトリを追加して改善します
buildscript {
repositories {
jcenter()
maven { url “https://maven.google.com” } // 追加
}
dependencies {
classpath ‘com.android.tools.build:gradle:3.0.0-alpha3′
}
}
はじめに
AndroidStudio作成のgradle環境のプロジェクトをコマンド実行します。
gradleコマンドは全環境に依存しているため、プロジェクト毎に関連性を持つGradleをラップしたgradlewコマンドを使います。
前回作成のプロジェクトをコマンド実行してみます
[Android]Gradleファイルで環境ごとに処理を切り分け(APK名・Keystore設定など)
プロジェクトは以下
https://github.com/y-matsumoto/template-project
タスク確認
プロジェクト直下にgradlew.batができてます。こちらを使います。
まずはプロジェクト直下に移動して以下のコマンドを実行し、タスク一覧を確認します
$ gradlew tasks Parallel execution with configuration on demand is an incubating feature. :tasks ------------------------------------------------------------ All tasks runnable from root project ------------------------------------------------------------ Android tasks ------------- androidDependencies - Displays the Android dependencies of the project. signingReport - Displays the signing info for each variant. sourceSets - Prints out all the source sets defined in this project. Build tasks ----------- assemble - Assembles all variants of all applications and secondary packages. assembleAndroidTest - Assembles all the Test applications. assembleDebug - Assembles all Debug builds. assembleDevelop - Assembles all Develop builds. assembleProduct - Assembles all Product builds. assembleRelease - Assembles all Release builds. assembleStaging - Assembles all Staging builds. build - Assembles and tests this project. buildDependents - Assembles and tests this project and all projects that depend on it. buildNeeded - Assembles and tests this project and all projects it depends on. clean - Deletes the build directory. compileDevelopDebugAndroidTestSources compileDevelopDebugSources compileDevelopDebugUnitTestSources compileDevelopReleaseSources compileDevelopReleaseUnitTestSources compileProductDebugAndroidTestSources compileProductDebugSources compileProductDebugUnitTestSources compileProductReleaseSources compileProductReleaseUnitTestSources compileStagingDebugAndroidTestSources compileStagingDebugSources compileStagingDebugUnitTestSources compileStagingReleaseSources compileStagingReleaseUnitTestSources mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests. Build Setup tasks ----------------- init - Initializes a new Gradle build. [incubating] wrapper - Generates Gradle wrapper files. [incubating] Help tasks ---------- components - Displays the components produced by root project 'template-project'. [incubating] dependencies - Displays all dependencies declared in root project 'template-project'. dependencyInsight - Displays the insight into a specific dependency in root project 'template-project'. help - Displays a help message. model - Displays the configuration model of root project 'template-project'. [incubating] projects - Displays the sub-projects of root project 'template-project'. properties - Displays the properties of root project 'template-project'. tasks - Displays the tasks runnable from root project 'template-project' (some of the displayed tasks may belong to subprojects). Install tasks ------------- installDevelopDebug - Installs the DebugDevelop build. installDevelopDebugAndroidTest - Installs the android (on device) tests for the DevelopDebug build. installProductDebug - Installs the DebugProduct build. installProductDebugAndroidTest - Installs the android (on device) tests for the ProductDebug build. installStagingDebug - Installs the DebugStaging build. installStagingDebugAndroidTest - Installs the android (on device) tests for the StagingDebug build. uninstallAll - Uninstall all applications. uninstallDevelopDebug - Uninstalls the DebugDevelop build. uninstallDevelopDebugAndroidTest - Uninstalls the android (on device) tests for the DevelopDebug build. uninstallDevelopRelease - Uninstalls the ReleaseDevelop build. uninstallProductDebug - Uninstalls the DebugProduct build. uninstallProductDebugAndroidTest - Uninstalls the android (on device) tests for the ProductDebug build. uninstallProductRelease - Uninstalls the ReleaseProduct build. uninstallStagingDebug - Uninstalls the DebugStaging build. uninstallStagingDebugAndroidTest - Uninstalls the android (on device) tests for the StagingDebug build. uninstallStagingRelease - Uninstalls the ReleaseStaging build. Verification tasks ------------------ check - Runs all checks. connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices. connectedCheck - Runs all device checks on currently connected devices. connectedDevelopDebugAndroidTest - Installs and runs the tests for developDebug on connected devices. connectedProductDebugAndroidTest - Installs and runs the tests for productDebug on connected devices. connectedStagingDebugAndroidTest - Installs and runs the tests for stagingDebug on connected devices. deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers. deviceCheck - Runs all device checks using Device Providers and Test Servers. lint - Runs lint on all variants. lintDevelopDebug - Runs lint on the DevelopDebug build. lintDevelopRelease - Runs lint on the DevelopRelease build. lintProductDebug - Runs lint on the ProductDebug build. lintProductRelease - Runs lint on the ProductRelease build. lintStagingDebug - Runs lint on the StagingDebug build. lintStagingRelease - Runs lint on the StagingRelease build. test - Run unit tests for all variants. testDevelopDebugUnitTest - Run unit tests for the developDebug build. testDevelopReleaseUnitTest - Run unit tests for the developRelease build. testProductDebugUnitTest - Run unit tests for the productDebug build. testProductReleaseUnitTest - Run unit tests for the productRelease build. testStagingDebugUnitTest - Run unit tests for the stagingDebug build. testStagingReleaseUnitTest - Run unit tests for the stagingRelease build. Other tasks ----------- clean jarDevelopDebugClasses jarDevelopReleaseClasses jarProductDebugClasses jarProductReleaseClasses jarStagingDebugClasses jarStagingReleaseClasses lintVitalDevelopRelease - Runs lint on just the fatal issues in the DevelopRelease build. lintVitalProductRelease - Runs lint on just the fatal issues in the ProductRelease build. lintVitalStagingRelease - Runs lint on just the fatal issues in the StagingRelease build. To see all tasks and more detail, run gradlew tasks --all To see more detail about a task, run gradlew help --task <task> BUILD SUCCESSFUL Total time: 4.033 secs
Androidプロジェクトのビルド
タスクにより端末にインストールや、ビルド、APKファイル作成を指定環境ごとに作成します。
試しにassembleReleaseタスクを実行します
$ gradlew assembleDebug Parallel execution with configuration on demand is an incubating feature. :app:preBuild UP-TO-DATE :app:preDevelopDebugBuild UP-TO-DATE :app:checkDevelopDebugManifest :app:preDevelopReleaseBuild UP-TO-DATE :app:preProductDebugBuild UP-TO-DATE :app:preProductReleaseBuild UP-TO-DATE :app:preStagingDebugBuild UP-TO-DATE :app:preStagingReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE :app:prepareComAndroidSupportDesign2221Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE :app:prepareDevelopDebugDependencies :app:compileDevelopDebugAidl UP-TO-DATE :app:compileDevelopDebugRenderscript UP-TO-DATE :app:generateDevelopDebugBuildConfig UP-TO-DATE :app:generateDevelopDebugAssets UP-TO-DATE :app:mergeDevelopDebugAssets UP-TO-DATE :app:generateDevelopDebugResValues UP-TO-DATE :app:generateDevelopDebugResources UP-TO-DATE :app:mergeDevelopDebugResources UP-TO-DATE :app:processDevelopDebugManifest UP-TO-DATE :app:processDevelopDebugResources UP-TO-DATE :app:generateDevelopDebugSources UP-TO-DATE :app:processDevelopDebugJavaRes UP-TO-DATE :app:compileDevelopDebugJavaWithJavac UP-TO-DATE :app:compileDevelopDebugNdk UP-TO-DATE :app:compileDevelopDebugSources UP-TO-DATE :app:preDexDevelopDebug UP-TO-DATE :app:dexDevelopDebug UP-TO-DATE :app:validateDebugSigning :app:packageDevelopDebug :app:zipalignDevelopDebug :app:assembleDevelopDebug :app:checkProductDebugManifest :app:prepareProductDebugDependencies :app:compileProductDebugAidl UP-TO-DATE :app:compileProductDebugRenderscript UP-TO-DATE :app:generateProductDebugBuildConfig UP-TO-DATE :app:generateProductDebugAssets UP-TO-DATE :app:mergeProductDebugAssets UP-TO-DATE :app:generateProductDebugResValues UP-TO-DATE :app:generateProductDebugResources UP-TO-DATE :app:mergeProductDebugResources UP-TO-DATE :app:processProductDebugManifest UP-TO-DATE :app:processProductDebugResources UP-TO-DATE :app:generateProductDebugSources UP-TO-DATE :app:processProductDebugJavaRes UP-TO-DATE :app:compileProductDebugJavaWithJavac UP-TO-DATE :app:compileProductDebugNdk UP-TO-DATE :app:compileProductDebugSources UP-TO-DATE :app:preDexProductDebug UP-TO-DATE :app:dexProductDebug UP-TO-DATE :app:packageProductDebug :app:zipalignProductDebug :app:assembleProductDebug :app:checkStagingDebugManifest :app:prepareStagingDebugDependencies :app:compileStagingDebugAidl UP-TO-DATE :app:compileStagingDebugRenderscript UP-TO-DATE :app:generateStagingDebugBuildConfig UP-TO-DATE :app:generateStagingDebugAssets UP-TO-DATE :app:mergeStagingDebugAssets UP-TO-DATE :app:generateStagingDebugResValues UP-TO-DATE :app:generateStagingDebugResources UP-TO-DATE :app:mergeStagingDebugResources UP-TO-DATE :app:processStagingDebugManifest UP-TO-DATE :app:processStagingDebugResources UP-TO-DATE :app:generateStagingDebugSources UP-TO-DATE :app:processStagingDebugJavaRes UP-TO-DATE :app:compileStagingDebugJavaWithJavac UP-TO-DATE :app:compileStagingDebugNdk UP-TO-DATE :app:compileStagingDebugSources UP-TO-DATE :app:preDexStagingDebug UP-TO-DATE :app:dexStagingDebug UP-TO-DATE :app:packageStagingDebug :app:zipalignStagingDebug :app:assembleStagingDebug :app:assembleDebug BUILD SUCCESSFUL Total time: 5.978 secs
BUILD SUCCESSFULで成功です。
template-project\app\build\outputs\apkディレクトリにdebugモードで各環境(develop,staging,product)でapkファイルが作成されます。
環境毎に実行する場合はassembleDevelop,assembleStaging,assembleProductタスクを実行してください。debug,releaseでファイルが作成されます。
ant,mavenより簡単で早いですね。
はじめに
Gradleの設定ファイルを修正することでdebugモード、releaseモードで処理を切り分け設定を有効化できるので、設定しておきます。
1.keystore設置
keystoreもdebugとreleaseでアップしておくとビルドが楽なのでいいと思います。
ただ、release用はgitなどでサーバプッシュはしないほうがセキュリティ的に良いと思います。
keystoreというディレクトリ名にしてプロジェクト直下に作成し、中にkeystoreファイルをそれぞれ設置してください。
2.Gradleファイルについて
設定プロパティなど詳細は公式を参照ください
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types
Gradleファイルのベースとなるテンプレートをアップしておきます。適時変えて使ってみてください。
実行時はAndroidStudioよりBuild VariantからdevelopDebug,stagingDebug,productDebug,developRelease,stagingRelease,productReleaseより選択して実行してください。
実行したできたapkは「app\build\outputs\apk」に作成されます。
実行した場合のapkファイル名のフォーマットは以下になります
[パッケージ名簡潔]_r[バージョン名]-[環境名]-[モード名(release or debug)]_r[バージョンコード]_[実行日付].apk」
app-[環境名]-[モード名(release or debug)]-unaligned.apk」になります。
デフォルトインポートについて
よく使うjava系(java.lang、java.io、java.math、java.net、java.util)はすでにimportされているので、Dateなどその場で使えます。
足りないものはimportで「import java.text.SimpleDateFormat」のように追加できます。
詳細は以下より確認ください。
3.2.1. Default imports
All these packages and classes are imported by default, i.e. you do not have to use an explicit import statement to use them:java.io.*
java.lang.*
java.math.BigDecimal
java.math.BigInteger
java.net.*
java.util.*
groovy.lang.*
groovy.util.*
http://docs.groovy-lang.org/latest/html/documentation/index.html#_differences_with_java
productFlavors
productFlavorsは実行環境毎に処理を切り分けるために使用できます。今回は環境ごとにファイル名に環境を付加する設定です。
3.その他ファイルの環境別切り分け(develop,staging,product)
productFlavorsで実行環境の処理を切り分けた場合、その環境名と同名のディレクトリを作成すると環境ごとに読み込みディレクトリを自動的に変えてくれます。
今回はstring.xmlのアプリ名となる
ディレクトリは以下のようにします
│ └─src │ ├─develop │ │ └─res │ │ └─values │ │ └─strings.xml │ ├─main │ │ ├─java │ │ │ └─hogehoge │ │ └─res │ │ ├─drawable │ │ ├─drawable-v21 │ │ ├─layout │ │ ├─menu │ │ ├─mipmap-hdpi │ │ ├─mipmap-mdpi │ │ ├─mipmap-xhdpi │ │ ├─mipmap-xxhdpi │ │ ├─mipmap-xxxhdpi │ │ ├─values │ │ └─strings.xml │ │ ├─values-v21 │ │ └─values-w820dp │ ├─product │ │ └─res │ │ └─values │ │ └─strings.xml │ ├─staging │ │ └─res │ │ └─values │ │ └─strings.xml
Build Variantから環境ごとにビルドして実行すると確認できます。
一式をテンプレートプロジェクトとしてgithubにアップしました
https://github.com/y-matsumoto/template-project
はじめに
Android開発ではbuild.gradle(Eclipse開発の場合はmanifestファイル)にminSDKVersion,TargetSDKVersionを記載します。この設定によりアプリのバージョン対応をします。
minSDKVersion設定は特に重要で、このバージョンより下位にあたるバージョンの端末ではアプリは実行できません。
Androidの記事を見ていると稀に、コードネームでバージョンを記載している場合も多いです。※Androidではコードネームがお菓子に関連した名前になっています
いまだ2015/11/19時点で2.3.3バージョン(APIレベル10)もシェア3%いるため、捨てるか迷いますが、これから作成するアプリはminSDKVersionは4.1(APIレベル16)にしておけばよいと思います。
公式ページに一覧一式掲載されています。
公式APIレベル
http://developer.android.com/intl/ja/guide/topics/manifest/uses-sdk-element.html
公式バージョンシェア率 ※頻繁に更新されているため信頼あるデータです
http://developer.android.com/intl/ja/about/dashboards/index.html
バージョン毎の変更点など
https://ja.wikipedia.org/wiki/#Android_6.0_Marshmallow
Androidバージョンと対応するAPIレベル/コードネーム一覧
coffee-break
Don't write code that useless.
1日5杯はコーヒー、カフェオレ飲みます。狭心症のため安静にします☆松本 雄貴
Kotlinでサービスリリース目指す!
iOSでチャットアプリ作成中。自然言語解析LSIを習得中
Mac / Android・iOS / Rails / Oracle
2017年 Lpic L2取得
2012年 Android技術者資格取得
2010年 OracleMasterGold10g取得
2008年 CCNAQiitaもたまに投稿
https://qiita.com/y-matsumoto東京近郊で常駐開発探してる方はこちらよりご連絡ください
SES企業でパートナー会社を探している企業様はこちらよりご連絡ください
スプリットカメラ iOS / Android
音声認識で聞いた日付から曜日当てアプリ Android
ソーシャルタイマー Android
カテゴリー
- ActiveRecord (2)
- Android (52)
- AndroidStudio (10)
- Ansible (1)
- AWS (1)
- Bash (18)
- Blog (7)
- BootStrap (1)
- CentOS (16)
- Chef (1)
- css (2)
- Eclipse (5)
- error (1)
- Facebook (2)
- Firebase (1)
- FuelPHP (16)
- Git (22)
- GitHub (3)
- Gradle (2)
- GraphAPI (1)
- Grunt (1)
- heroku (2)
- illustrator (1)
- iOS (17)
- Java (4)
- Jenkins (1)
- jQuery (3)
- Kotlin (2)
- Mac (22)
- nginx (1)
- Node.js (3)
- peco (1)
- php (5)
- Python (1)
- Rails (16)
- Ruby (11)
- shell (1)
- SNS (1)
- Swift (2)
- tmux (2)
- Vagrant (6)
- Vim (6)
- windows (2)
- WordPress (3)
- zsh (4)
- フリーランス (1)
- ライブラリ (1)
- 勉強会 (2)
- 宣伝 (1)
- 未分類 (2)
最近の投稿
- [MAC]HighSierraでgitプッシュエラー「Unable to negotiate with xxx.xxx.xxx.xxx port xx: no matching cipher found. Their offer: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se fatal: Could not read from remote repository.」
- [iOS]iOS11からFacebook,Twitter連携(シェアなど)廃止の対応方法
- [iOS]速報2017AppleSpecialEventのiOS11、iPhone8など発表内容について
- [iOS][Firebase]The default Firebase app has not yet been configured. Add `[FIRApp configure];
- [iOS]2017年9月リリースのiOS11で開発者が対応するべきこと
- 今人気の現金化サービスCASH(キャッシュ)を使ったレビュー
- [Pandoc][Mac]pandocでmarkdownからwordファイル作成
- [Android]映画サマーウォーズの聞いた日付(誕生日)から曜日当てをアプリ音声認識で簡単に実現
- [Android]起動しているActivityを取得するadb shell コマンド
- [Android][Kotlin]kotlin学習で参考になるサイト一覧
2023年12月 月 火 水 木 金 土 日 « 5月 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 アーカイブ
- 2018年5月
- 2017年9月
- 2017年8月
- 2017年7月
- 2017年6月
- 2017年5月
- 2017年2月
- 2017年1月
- 2016年12月
- 2016年7月
- 2016年6月
- 2016年1月
- 2015年12月
- 2015年11月
- 2015年10月
- 2015年9月
- 2015年8月
- 2015年7月
- 2015年6月
- 2015年5月
- 2015年4月
- 2015年3月
- 2015年2月
- 2015年1月
- 2014年12月
- 2014年11月
- 2014年6月
- 2014年5月
- 2014年4月
- 2014年3月
- 2014年2月
- 2014年1月
- 2013年12月
- 2013年11月
- 2013年9月
- 2013年8月
- 2013年7月
- 2013年6月
- 2013年5月
- 2013年4月
- 2013年3月
- 2013年2月
- 2013年1月
- 2012年12月
- 2012年10月
- 2012年5月
- 2010年6月
エントリ