0

While trying to use google maps v2 for application as suggested by this link i went about the procedure to get the key and then followed the procedure for importing google play service.But when i import the library in my project i find R file is missing. Can anyone suggest how this error can be solved.

EDIT

Code and the log cat for it.

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"/>

and then the permission given in the manifest file

<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

sankettt
  • 2,387
  • 4
  • 23
  • 31
  • It has something to do with your manifest file try scanning your manifest for broken tags and wrong attributes. – Ariel Magbanua Feb 23 '13 at 18:31
  • @hardcoded i have posted my snipet of my manifest file can you check it and let me know if i am missing something – sankettt Feb 26 '13 at 05:40
  • By the way, did you run your application and got this logcat stack trace? If so then your R class now works fine? – Ariel Magbanua Feb 26 '13 at 09:55
  • check the logcat that i have posted now the R file error is not there rather gives me `ClassNotFoundException` and the class which its giving error is `com.google.android.gms.R$styleable` – sankettt Feb 26 '13 at 13:10
  • @sankettt: Have you got any solution..?? – Mitesh Shah Feb 10 '14 at 07:00

2 Answers2

0

Restart your project, run a clean and rebuild your project. If the problem remains try to check if there are other errors in other files. Try to edit and save de AndroidManifest.xml if the problem still remains.

red_alert
  • 1,738
  • 14
  • 24
  • Just edit some line, save, and rollback after that. When you save the manifest, the project will rebuild. I've suggested that because for me worked one of the times that I have your error. – red_alert Feb 19 '13 at 13:06
  • probably you need to change the project property and project must be using google api target. e.g. API 10 Google Inc. – Anuj Sharma Feb 19 '13 at 13:25
  • Right Click on the project-->Click on properties-->Click on android-->Select Google api 2.3.3 API 10. i hope this must solve your problem. – Anuj Sharma Feb 20 '13 at 05:53
  • did you try with other google api's like with lower one ? Api 10? – Anuj Sharma Feb 20 '13 at 06:35
  • I tried everything as @AnujSharma said...but still the problem persists. When working with other project it works perfect and it gets imported – sankettt Jul 06 '13 at 10:10
0

The problem might be this one.

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)

Because I think you have used.

<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"/>

It should be.

 <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"/>

The Google play services library uses SupportMapFragment not the MapFragment. You can also see it in their google map demo that they have used the SupportMapFragment.

Ariel Magbanua
  • 3,083
  • 7
  • 37
  • 48
  • Not working dude.. Please provide a feasible solution.. When I import google-play-service-lib. R.java file gets deleted.. – Mitesh Shah Feb 10 '14 at 06:59
  • @Mitesh do you have same problem with this one? Check your manifest most likely you made a mistake on tags in manifest. Did you posted your problem? If you have you can reply it here and I will look into it. – Ariel Magbanua Feb 12 '14 at 15:04
  • @Arman:: Thanks for replying.. Please check my problem.. http://stackoverflow.com/questions/21677327/android-deletes-r-java-file-when-importing-google-play-services-lib – Mitesh Shah Feb 13 '14 at 05:22