在android项目中导入Google-Play-Services会删除R文件

时间:2013-02-19 12:32:24

标签: android eclipse google-maps android-maps-v2 google-play-services

在按照this link的建议尝试使用google maps v2进行应用时,我开始了解获取密钥的过程,然后按procedure 导入google play服务。但是当我导入库时在我的项目中,我发现R文件丢失了。任何人都可以建议如何解决这个错误。

编辑

代码和它的日志猫。

public class Maptest extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maplayout);
    }
}

XML FIle:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/map"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  class="com.google.android.gms.maps.MapFragment"/>

然后是清单文件中给出的权限

<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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="com.curioussolutions.autoistdiary.permission.MAPS_RECEIVE"
      android:protectionLevel="signature"/>
    <uses-permission android:name="com.curioussolutions.autoistdiary.permission.MAPS_RECEIVE"/>

  <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

02-20 10:30:16.093: E/AndroidRuntime(21076): FATAL EXCEPTION: main 02-20 10:30:16.093: E/AndroidRuntime(21076): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable 02-20 10:30:16.093: E/AndroidRuntime(21076): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source) 02-20 10:30:16.093: E/AndroidRuntime(21076): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:271) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.view.LayoutInflater.inflate(LayoutInflater.java:408) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 02-20 10:30:16.093: E/AndroidRuntime(21076): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.Activity.setContentView(Activity.java:1657) 02-20 10:30:16.093: E/AndroidRuntime(21076): at com.curioussolutions.autoistdiary.MainActivity.onCreate(MainActivity.java:25) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.os.Handler.dispatchMessage(Handler.java:99) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.os.Looper.loop(Looper.java:130) 02-20 10:30:16.093: E/AndroidRuntime(21076): at android.app.ActivityThread.main(ActivityThread.java:3687) 02-20 10:30:16.093: E/AndroidRuntime(21076): at java.lang.reflect.Method.invokeNative(Native Method) 02-20 10:30:16.093: E/AndroidRuntime(21076): at java.lang.reflect.Method.invoke(Method.java:507) 02-20 10:30:16.093: E/AndroidRuntime(21076): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 02-20 10:30:16.093: E/AndroidRuntime(21076): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 02-20 10:30:16.093: E/AndroidRuntime(21076): at dalvik.system.NativeStart.main(Native Method) 02-20 10:30:17.500: W/jdwp(21076): Debugger is telling the VM to exit with code=1 02-20 10:30:17.500: I/dalvikvm(21076): GC lifetime allocation: 2194 bytes

2 个答案:

答案 0 :(得分:0)

重新启动项目,运行清理并重建项目。如果问题仍然存在,请尝试检查其他文件中是否存在其他错误。如果问题仍然存在,请尝试编辑并保存de AndroidManifest.xml。

答案 1 :(得分:0)

问题可能就是这个问题。

com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 02-20 10:30:16.093: E/AndroidRuntime(21076): 
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:271)

因为我认为你已经使用过了。

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment"/>

应该是。

 <fragment xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/map"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 class="com.google.android.gms.maps.SupportMapFragment"/>

Google Play服务库使用SupportMapFragment而不是MapFragment。您还可以在他们使用SupportMapFragment的Google地图演示中看到它。