3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

play-service ライブラリを導入 & エラーメモ

Last updated at Posted at 2015-08-06

外部プロジェクト(Eclipseベース)を
AndroidStudioにインポートしたときに四苦八苦したのでメモ。

0.背景

play-serviceを使うAndroidアプリがあり
これはもともとEclipseで開発されていたものでした。

そのプロジェクトファイルを一式、AndroidStudioへインポートしたら
以下のようなエラーがでインポートできない。

  • Project $PROJECT_NAME:/Users/mac/import_eclipse_project/project.properties:
    Library reference ../google-play-services_lib could not be found
    Path is /Users/mac/import_eclipse_project/../google-play-services_lib which resolves to /Users/mac/google-play-services_lib

「Eclipseでコンパイルリンク指定していた
google-play-serviceのプロジェクトあらへんで!!」

ということだと思う。

不要ファイルを削除してインポートして、
後からgoogle-playライブラリをコンパイル対象に指定することにしました。

そこからスタート。

1. google-playライブラリをgradleに加える

アプリのbuild.gradleに対して以下を追記。

build.gradle
dependencies {
    compile 'com.google.android.gms:play-services:+'
}

ちなみに、AndroidStudioではGUIからでも設定が可能みたいです。

ファイル > プロジェクト構造 > app >Dependencies
「+」から追加するライブラリを選択する

2. エラーが発生したよ!

ここでエラーが発生しない人もいると思います。
私はここで2回もエラーが発生したのでメモメモ。

2-1. packageAllDebugClassesForMultiDex エラー

これはGoogleAnalyticsのライブラリもコンパイル対象にしてると発生する。

エラー :Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/google/android/gms/analytics/internal/Command$1.class

GoogleAnalyticsライブラリが被ってるよ!!!
というエラー。

play-servicesライブラリにGoogleAnalyticsのライブラリが含まれているので
こういうエラーが起こるそうです。

プロジェクトによって対応は変わるみたいですが、
私の場合はplay-services-gcmと限定的にすることで解決。

build.gradle
dependencies {
    //compile 'com.google.android.gms:play-services:
    compile 'com.google.android.gms:play-services-gcm:
}

2-2. buttonBarStyleエラー

/Users/mac/StudioProjects/importproject/app/src/main/res/values/styles.xml
エラー :(25, 21) No resource found that matches the given name: attr 'buttonBarButtonStyle'.
エラー :(24, 21) No resource found that matches the given name: attr 'buttonBarStyle'.
/Users/hiroki/StudioProjects/02_cw_watch_app_versionup/app/src/main/res/values-v11/styles.xml
エラー :(20, 21) No resource found that matches the given name: attr 'buttonBarButtonStyle'.
エラー :(19, 21) No resource found that matches the given name: attr 'buttonBarStyle'.
エラー :Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/mac/Library/Android/sdk/build-tools/21.1.2/aapt'' finished with non-zero exit value 1

リソースファイルをみてみると、確かにエラー文にある
buttonBarStyle系が定義されている。

しかしこれは、プロジェクト作成すると自動生成されるもの。
正直、なくてもいい。消してあげれば解決。

x.参考文献

重複ライブラリ参照エラー
開発ツールが用意してくれるファイルでエラー
MultipulDex エラー(この記事とは結果的に関係なかったもの。メモで残しておきます)

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?