Android的工作室,谷歌MapFragment - mapv2 [英] Android Studio , Google MapFragment - mapv2
问题描述
我知道有这个问题很多,但它大约2天我在这工作,我无法找到正确的解决方案(我是新到Android)。我需要创建一个应用程序,可以处理地图和绘制一些标记。我甚至不能显示在地图我的设备上:( Nexus4
i know there are many question about this but it's about 2 days i work on this and i was unable to find a correct solution (i'm new to android). I need to create an app that can handle a map and draw some markers. I can't even show a map on my device :( Nexus4
这是我做了什么:
我在谷歌播放-services.jar复制到我的库目录,改变gradle.build来处理新的库:
i copy the google-play-services.jar into my libs dir and change the gradle.build to handle the new library :
dependencies {
compile files('libs/android-support-v4.jar' , 'libs/gcm.jar', 'libs/google-play-services.jar')
}
我已经签署了我的应用程序,也使mapv2 API和更改Android清单如下:
i already signed my app and enabled the mapv2 api and change the android manifest like this :
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
...
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.metu.xxx.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.metu.xxx.permission.MAPS_RECEIVE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="SIGNATURE_HERE -> ^_^"/>
...
我的Java类看起来是这样的:
my java class looks like this :
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class AtmActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_atm);
}
}
我的XML布局是这样的:
my xml layout looks like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
编写本code是好的,但是当我点击按钮,显示该活动的应用程序崩溃:(
这是错误日志:
compiling this code is ok but when i tap on the button to show the activity the app crash :( This is the error log :
06-16 13:34:30.957 523-535/? E/qcom_sensors_hal: hal_process_time_resp: Resetting rollover count from 0 to 0
06-16 13:34:39.716 28726-28726/com.metu.xxx E/AndroidRuntime: 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:676)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
at android.app.Activity.setContentView(Activity.java:1881)
at com.metu.xxx.AtmActivity.onCreate(AtmActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
有人能帮助我吗?
或者可以链接一个好如何解决此问题?
Somebody can help me ? or maybe can link a good how to to solve this ?
谢谢,对不起我的英文不好:)
Thanks and sorry for my poor english :)
更新:
似乎完全地我错了这一点。
it seems i completly wrong with this.
下面这个教程,并一切正常: http://android.rzeszow.net/?p= 79
following this tutorial and everything went fine : http://android.rzeszow.net/?p=79
(没有在文件拷贝缺少的一部分,你需要复制的jar和模块的库文件中的设置)
(there is a part missing in the copy files, you need to copy the jar and the settings to the libs file of the module)
推荐答案
您需要引用谷歌发挥服务项目,不仅罐子。
You need to reference google play services project and not only the jar.
这篇关于Android的工作室,谷歌MapFragment - mapv2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!