EclipseのプロジェクトをAndroid Studioへインポート時に出たエラー対処方法
重い腰を上げて、EclipseのプロジェクトをAndroid Stuidoへインポートした。 インポート自体はAndroid StudioからImport Projectをすれば良いのだが、エラーがいっぱい出てた。私が必要だった変更をまとめる。
1. minSdkVersionの設定
以下のエラーメッセージが出てきた。
Manifest merger failed : uses-sdk:minSdkVersion 10 cannot be smaller than version 14 declared in library [com.google.android.gms:play-services:10.2.1]
2017/04/03現在、ほとんどがversion 14以上だと思うので、プロジェクト内の全部のminSdkVersionを14にした。
2. compileSdkVersionの変更
以下のようなエラーが出た。
Error retrieving parent for item: No resource found that matches the given name ‘android:Widget.Material.Spinner.Underlined’.
compileSdkVersionをbuildToolsVersionと合わせないとダメなようだ。
buildToolsVersion “25.0.2”
だったので
compileSdkVersion 19
から
compileSdkVersion 25
に変更した。 すべてのbuild.gradleで変更した。
3. FloatMath
エラー: シンボルを見つけられません シンボル: メソッド sin(float) 場所: クラス FloatMath
ってのが出たから すべてのFloatMathをMathに変更した。
4. org.apache.http.legacy
パッケージorg.apache.httpは存在しません
とかのエラーが出てしまう。
build.gradleにuseLibrary ‘org.apache.http.legacy’ を追加すれば解決した。
以下のような感じ
android { compileSdkVersion 25 buildToolsVersion "25.0.2" useLibrary 'org.apache.http.legacy'
5. This support library should not use a different version
compile ‘com.android.support:support-v4:19.1.0’
で、This support library should not use a different versionというエラーメッセージが出ている。 19を25に変更すれば、エラーは消える。ついでに最新にしておく。
compile ‘com.android.support:support-v4:25.3.1’
6. All com.android.support libraries must use the exact same version
compile ‘com.android.support:support-v4:25.3.1’
にて
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.1.1, 24.0.0. Examples include com.android.support:animated-vector-drawable:25.1.1 and com.android.support:mediarouter-v7:24.0.0
とかいうエラーメッセージが出た。
compile ‘com.google.android.gms:play-services:+’
が原因のようで、 必要なものだけ追加するようにする。
例。
compile ‘com.google.android.gms:play-services-ads:10.2.1’
7. 不要なパーミッション
Android Studioでは自動でパーミッションがついてしまう。 不要なパーミッションがついて、プライバシーポリシーを追加しなくてはならなくなったりする。 ので、極力減らす。
原因1
Google Play Serviceが原因で追加されてしまう。 以下のように全て追加するのはやめる。
compile ‘com.google.android.gms:play-services:+’
以下のように必要なものだけ追加するように変更する。
compile ‘com.google.android.gms:play-services-ads:10.2.1’
原因2
インポートしている外部ライブラリで、minSdkVersionを明記しないと不要なパーミッションがついてしまう。
build/intermediates/manifets/full/の中にあるマージ後のAndroidManifestを確認すると 以下の2行が追加されてしまっていた。
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
最初はGoogle Play Serviceのせいかと思ったが、外部ライブラリのせいだった。 外部ライブラリでminSdkVersionを設定すれば解決した。 外部ライブラリのbuild.gradleにて
defaultConfig { minSdkVersion 14 }
その他、状況によってはtargetSdkVersionを指定する必要もあるようだ。
以上