Domanda

OK, so I've read something like 10 other threads here regarding this infamous issue, and tried every possible solution offered - without any luck.

I have a Phonegap project that I worked on a few months ago, and have to create a new version now. So, on my new Mac - the old Mac is no longer available to me, I checked out the code which I used to make the previous build (so there can't be anything wrong with the actual code, since it hasn't changed). Since my new Mac didn't have Eclipse installed I downloaded the Android SDK and discovered it came with a preconfigured version of Eclipse, so I used that.

Just to be on the safe side I have installed all the SDK versions. Sadly I have to target Android 2.3.3, with a minimum version of 2.1. I have made sure this is configured correctly in the project.

All my .xml and .png files under the "res" folder have valid lowercase names. There are no errors in the XML files, at least Eclipse doesn't complain about anything in them - and like I stated above, the XML files haven't changed since the last time I successfully built the app.

I have made sure the permissions of the Android Developer Tools are correct (everyone has read access).

I have deleted the "gen" folder and tried building again. I've done "clean" countless times. I've restarted Eclipse countless times.

I have made sure the package names are synchronized everywhere. I have made sure I don't have "import android.R" anywhere.

The "gen" folder is created every time Eclipse tries to build, but it doesn't include the R.java file, it only includes the file BuildConfig.java which in addition to the package declaration contains this:

public final class BuildConfig {
    public final static boolean DEBUG = true;
}

My res/values/strings.xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World</string>
    <string name="app_name">My App Name</string>

</resources>

My res/xml/plugins.xml file contains this:

<?xml version="1.0" encoding="utf-8"?>
<plugins>
    <plugin name="App" value="com.phonegap.App"/>
    <plugin name="Geolocation" value="com.phonegap.GeoBroker"/>
    <plugin name="Device" value="com.phonegap.Device"/>
    <plugin name="Accelerometer" value="com.phonegap.AccelListener"/>
    <plugin name="Compass" value="com.phonegap.CompassListener"/>
    <plugin name="Media" value="com.phonegap.AudioHandler"/>
    <plugin name="Camera" value="com.phonegap.CameraLauncher"/>
    <plugin name="Contacts" value="com.phonegap.ContactManager"/>
    <plugin name="Crypto" value="com.phonegap.CryptoHandler"/>
    <plugin name="File" value="com.phonegap.FileUtils"/>
    <plugin name="Network Status" value="com.phonegap.NetworkManager"/>
    <plugin name="Notification" value="com.phonegap.Notification"/>
    <plugin name="Storage" value="com.phonegap.Storage"/>
    <plugin name="Temperature" value="com.phonegap.TempListener"/>
    <plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
    <plugin name="Capture" value="com.phonegap.Capture"/>

    <plugin name="EncapPlugin" value="no.encap.securitytoken.phonegap.plugin.EncapPlugin" />
</plugins>

My res/layout/main.xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

I've tried changing fill_parent with match_parent above, since I read in one of the answers that it had been renamed to that in version 8 of the API - but that didn't help. Anyway, I need to support version 7 of the API as well. Just in case, I tried changing the names as stated and setting the minimum version to 8, but that didn't help.

Eclipse generates no other errors, and only one benign and unrelated warning, when trying to build.

My AndroidManifest.xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="no.encap.securitytoken.phonegap"
          android:versionCode="1"
          android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" /><supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application
            android:icon="@drawable/icon"
            android:label="@string/app_name" >
        <activity
                android:name="EncapMain"
                android:label="@string/app_name"
                android:configChanges="orientation|keyboardHidden"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity><activity
            android:name="com.phonegap.DroidGap"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name" >
        <intent-filter>
        </intent-filter>
    </activity>
    </application>

</manifest>

Since this is a PhoneGap app the XML files really only contain the bare minimum required to get a WebView up and running.

Anyone have any idea what could be wrong here? This R.java thing really seems like a very weak point for the Android Developer Tools - and improved handling of build errors related to this (explaining what is wrong) seems like a thing that could benefit from being prioritized. Anyway - I hope someone can help!

UPDATE: The problem is caused by Subversion. I'm not sure exactly what it is Subversion is doing that's causing this, but whenever I make a new project and import my files to get Eclipse to compile the project everything works fine. Then, whenever I do something in Subversion, like add/delete/commit/update an HTML, CSS or Javascript file (in the assets folder) this error returns and I have to make a new project again.

È stato utile?

Soluzione

I think you made little mistake in building of gen ..so check is there any sort of mistake in your xml file or generated file..

After clean and build also if its not working then do the simple work..

create new project copy the code and layout and the .png xml plugins etc don't even delete the gen folder then

After clean and build run project it will work

check this link for more help

Altri suggerimenti

Reasons for missing R.java could be

  • When you dont properly name your drawables
  • When there is some issue with your layouts
  • When you forget to register things (Activity etc) in AndroidManifest file
  • When there is a conflict in package name in manifest and some other place
  • Sometimes multiple pacakges can arise this issue

Tip: Look at the error in the Console and see where does it refer, that is the only lead !!

Fact: Cleaning the project does not solve the problem always

I had made an update of all sdk's and then I got the famous "R cannot...". Turns out all build-tools had been deleted during the update of the sdk's. Check "SDk Manager" that you have all tools installed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top