Google Maps Android v2不能与ActionBarSherlock片段活动一起使用
我已经按照使用ActionBarSherlock的步骤使用新的SupportMapFragment使用新的Google Maps Android v2 API,但是我收到一些导致应用程序在启动时崩溃的错误。
我在我的应用程序中使用Maven,所以我也发布了我的AndroidManifest和POM文件。
你能帮我吗?
以下是来自logcat的错误:
12-22 14:35:41.319:ERROR / AndroidRuntime(8565):致命异常:com.google.android.gms.maps.GoogleMapOptions中的main java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable。 android.view.LayoutInflater.createViewFromTag上的android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:269)上的com.google.android.gms.maps.SupportMapFragment.onInflate(未知源代码)中的createFromAttributes(未知源代码) (LayoutInflater.java:563)android.view.LayoutInflater.rInflate(LayoutInflater.java:623)android.view.LayoutInflater.inflate(LayoutInflater.java:408)android.view.LayoutInflater.inflate(LayoutInflater.java: 320)at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:262)android.view.LayoutInflater.inflate(LayoutInflater.java:276) )在br.com.myapp.activities.MainActivity.onCreate(MainActivity.java:19)at和 robin.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)at android.app.ActivityThread .access $ 1500(ActivityThread.java:117)at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop (Looper.java:130)at java.lang.reflect.Method.invoke(Method.java :507)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)at dalvik.system.NativeStart。主(本地方法)
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.myapp" android:versionCode="1" android:versionName="2.0.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"></uses-sdk>
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<permission android:name="br.com.myapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="br.com.myapp.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application android:label="@string/app_name" android:icon="@drawable/rp_icon"
android:logo="@drawable/logo_actionbar" android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MyKeyXXXXXXXXXXXXXXXXXXXXXXXXX" />
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
pom.xml中:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/maven-v4_0_0.xsd“> 4.0.0 br.com.myapp myapp-android 2.0.0 apk myapp
<properties>
<platform.version>4.2
</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>com.loopj.android.http</groupId>
<artifactId>async-http-client</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.2.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>10</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
您是否包含Google地图库的完整源代码? 这里有资源(因此引用com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)中的java.lang.NoClassDefFoundError:com.google.android.gms.R $ styleable)。
仅仅引用google-play-services.jar文件是不够的。 仔细检查Google Play Services项目根目录下的README.txt文件。
在我的项目中找到同样的问题。
解决方案是将com.google.android.gms的两个依赖关系添加到maven构建脚本中:apklib和jar:
<!-- google-play-services. -->
<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>
另外,map v2不需要依赖com.google.android.maps。
链接地址: http://www.djcxy.com/p/96813.html上一篇: Google Maps Android v2 not working with ActionBarSherlock Fragment Activity