R class has no "id" member

I’m following the “Your First Android App” tutorial for writing an Android app in Swift, and I’m stuck because the generated “R” class has no “id” member, making the following line of code from the tutorial invalid:

let button = findViewById(R.id.sayHelloButton) as! Button

I’m using Fire version 8.3.95.2031. How can I fix this problem?

The “R” class was updated with an “id” member after I restarted Fire.

1 Like

curious. does this problem persist with a new project?

Yes, I reproduced it today.

  1. Create new Swift on Android project.
  2. Build.
  3. Edit UI in android studio, and add two labels, a text field, and a button as described in the tutorial.
  4. Save all in android studio, and close android studio.
  5. Build in Fire.
  6. View the outline of the R class in the window on the left of Fire, and see that there is no “id” member.
  7. Close Fire entirely, then re-open Fire and the project.
    8.View the outline of the R class, and see that there is an “id” member.

Note that building between steps #7 and #8 was not required. Also, the problem does not occur if step #2 is skipped. If R isn’t generated for the first time until after the UI has been edited, R is generated properly, with an “id” member. Lastly, cleaning the build after step #4 just resulted in a different error, one that I haven’t been able to resolve:

    /Users/christophersimmons/Documents/repos/com.doclily.testRgen2/MainActivity.swift(13,17): error E46: Unknown identifier "R"
    /Users/christophersimmons/Documents/repos/com.doclily.testRgen2/MainActivity.swift(13,26): error E43: No static member "main" on type "android.R.layout"

Thanks, logged as bugs://76664

Hmm, i cant reproduce this. this is the layout i get from ADS:

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

	<LinearLayout
		android:orientation="vertical"
		android:layout_width="wrap_content"
		android:layout_height="match_parent"></LinearLayout>

	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="New Button"
		android:id="@+id/button" />

	<TextView
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:textAppearance="?android:attr/textAppearanceMedium"
		android:text="Medium Text"
		android:id="@+id/textView" />
</LinearLayout>

note the @+id thingies, thats what defines the Ids. does your layout have those? for mine, ADS gave the controls IDs automatically, no need for me to to anything but drop the button and save.

here’s my resulting R.java file, which has the id nested class, just fine…

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package com.remobjects.androidapplication8;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int button=0x7f050000;
        public static final int textView=0x7f050001;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040000;
    }
}

what could i be missing, steps wise? i have ADS 2.1.2

bugs://76664 got closed with status cannotrepro.

The only thing that I can imagine you’re doing differently is forgetting to build before editing the layout file. I can repro the issue by just opening a new project, building, copy-pasting the layout XML from your post, and building again. Furthermore, I now see that Fire is in general neglecting to update R until I restart it. After I have an R with an id class, if I remove all of the objects with IDs from the layout file and then build again, Fire doesn’t remove id from R until I restart Fire.

Hm, that makes no sense. Fire doesn’t generate the R file at all. Building is what creates it.

Logged as bugs://i64508.

bugs://i64508 was closed as unable to reproduce.