我尝试使用IntelliJ IDEA的12运行谷歌地图。
我已经尝试过建议:
- 嵌入谷歌地图在安卓机器人V2
- 谷歌地图API的Android V2授权失败
- 无法实例化android.gms.maps.MapFragment
- 谷歌地图API的Android给人的NoClassDefFoundError
等等。 但不幸的是,它不适合我的工作。
我的配置:
1)实时设备HTC wildefire S,机器人2.3.5
2)
3) AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.ergeslab.TransportScheduleYaroslavl" android:installLocation="auto" android:versionCode="1" android:versionName="1.0"> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <permission android:name="ru.ergeslab.TransportScheduleYaroslavl.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="ru.ergeslab.TransportScheduleYaroslavl.permission.MAPS_RECEIVE"/> <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" /> <application android:label="@string/app_name"> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MY_KEY"/> <uses-library android:name="com.google.android.maps" /> <activity android:name="MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
4) MainActivity:
<pre>
package ru.ergeslab.TransportScheduleYaroslavl;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
5) main.xml
:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" />
6)IDE项目设置:
完整的Android logcat的:
04-02 21:27:07.718: ERROR/AndroidRuntime(24277): FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source) at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) at android.view.LayoutInflater.inflate(LayoutInflater.java:386) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at android.view.LayoutInflater.inflate(LayoutInflater.java:276) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250) at android.app.Activity.setContentView(Activity.java:1712) at ru.ergeslab.TransportScheduleYaroslavl.MainActivity.onCreate(MainActivity.java:13) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851) at android.app.ActivityThread.access$1500(ActivityThread.java:132) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:4277) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method)
任何帮助是极大的赞赏。