使用Eclipse,我将几个谷歌地图v1转换为v2,没有遇到任何问题。我的一个服务大量使用V1 GeoPoint类,并且我能够通过导入import com.google.android.maps.GeoPoint
来不更改地使用代码。我有六个应用程序使用这个GeoPoint类运行地图V2。
现在,我已经完成了Android Studio将上一个maps V1应用程序转换为maps V2的工作,但即使我有相同的导入语句,当我引用GeoPoint类时,我在运行时也会遇到异常。说
NoClassDefFoundError:Lcom/google/android/maps/GeoPoint解析失败。
因此,在Eclipse中测试时,相同的代码运行良好,但在AndroidStudio中测试时会失败。
编辑:GeoPoint类在中编译得很好,因为它只是在运行时爆炸。我不知道是什么原因造成的。
如果有帮助的话,我会包含清单文件和模块Build.gradle
。
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.deanblakely.mttTrial"
minSdkVersion 10
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':library')
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.google.android.gms:play-services:+'
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deanblakely.mttTrial"
android:versionCode="22"
android:versionName="2.22" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="false"
android:xlargeScreens="true" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.deanblakely.mttTrial.PSActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>
<activity
android:label="@string/app_name"
android:name="com.deanblakely.mttTrial.LicenseCheck"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<uses-library android:name="com.google.android.maps" />
</activity>
<service
android:name="com.deanblakely.mttTrial.StalkService"
android:exported="false" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="not the actual key" />
<!--' Release key is not the actual release key'-->
<!--' Debug key is not the actual debug key'-->
</application>
<!-- Required permission to check licensing. -->
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
</manifest>
改进build.gradle
compile 'com.google.android.gms:play-services:5.0.89'
并将其添加到您的Manifest
<uses-permission android:name="com.deanblakely.mttTrial.permission.MAPS_RECEIVE" />