我正在使用谷歌地图和 maven 创建一个 android 应用程序。我在 pom.xml 中放入了两个依赖项
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>4</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>4</version>
<type>jar</type>
</dependency>
apklib 和 jar 出现在 maven 存储库中。(m2\repository)
main_map.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLay"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
我将权限和元数据与 api 密钥一起放在我的 AndroidManifest 中。
<permission
android:name="com.map.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.map.example.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permissionndroid:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDRDsq0vAYySrs__0a8Yb2yr333W_z1uAo" />
主要活动
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
private GoogleMap map;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_map.xml);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
}
}
我得到了这个例外
04-18 10:32:37.939: E/AndroidRuntime(21550): FATAL EXCEPTION: main
04-18 10:32:37.939: E/AndroidRuntime(21550): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-18 10:32:37.939: E/AndroidRuntime(21550): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-18 10:32:37.939: E/AndroidRuntime(21550): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:269)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-18 10:32:37.939: E/AndroidRuntime(21550): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.Activity.setContentView(Activity.java:1657)
04-18 10:32:37.939: E/AndroidRuntime(21550): at com.codespring.androidspeed.ui.newui.MainPager.onCreate(MainPager.java:62)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.os.Looper.loop(Looper.java:123)
04-18 10:32:37.939: E/AndroidRuntime(21550): at android.app.ActivityThread.main(ActivityThread.java:3729)
04-18 10:32:37.939: E/AndroidRuntime(21550): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 10:32:37.939: E/AndroidRuntime(21550): at java.lang.reflect.Method.invoke(Method.java:507)
04-18 10:32:37.939: E/AndroidRuntime(21550): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
04-18 10:32:37.939: E/AndroidRuntime(21550): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
04-18 10:32:37.939: E/AndroidRuntime(21550): at dalvik.system.NativeStart.main(Native Method)
任何人都可以帮助我吗?