diff --git a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt index 488975ad3ef..c5106fd0d75 100644 --- a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt +++ b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/lang/resolve/android/AndroidUIXmlProcessor.kt @@ -92,20 +92,19 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) { return resourceManager.getLayoutXmlFiles().flatMap { entry -> val files = entry.getValue() val widgets = parseLayout(files) - if (widgets.isNotEmpty()) { - val layoutPackage = files[0].genSyntheticPackageName() - val mainLayoutFile = renderLayoutFile(layoutPackage, widgets) { - writeSyntheticProperty("Activity", it, "findViewById(0)") - writeSyntheticProperty("Fragment", it, "getView().findViewById(0)") - } + val layoutPackage = files[0].genSyntheticPackageName() - val viewLayoutFile = renderLayoutFile("$layoutPackage.view", widgets) { - writeSyntheticProperty("View", it, "findViewById(0)") - } + val mainLayoutFile = renderLayoutFile(layoutPackage, widgets) { + writeSyntheticProperty("Activity", it, "findViewById(0)") + writeSyntheticProperty("Fragment", it, "getView().findViewById(0)") + } - listOf(mainLayoutFile, viewLayoutFile) - } else listOf() + val viewLayoutFile = renderLayoutFile("$layoutPackage.view", widgets) { + writeSyntheticProperty("View", it, "findViewById(0)") + } + + listOf(mainLayoutFile, viewLayoutFile) }.filterNotNull() + commonFiles } @@ -156,7 +155,7 @@ public abstract class AndroidUIXmlProcessor(protected val project: Project) { for (widget in widgets) { if (widgetMap.contains(widget.id)) { val existingElement = widgetMap.get(widget.id) - if (existingElement.className != widget.className) { + if (existingElement.className != widget.className && existingElement.className != "View") { // Widgets with the same id but different types exist. widgetMap.put(widget.id, widget.copy(className = "View")) } diff --git a/plugins/android-compiler-plugin/testData/android/converter/simple/noIds/layout.kt b/plugins/android-compiler-plugin/testData/android/converter/simple/noIds/layout.kt new file mode 100644 index 00000000000..63fabc25d12 --- /dev/null +++ b/plugins/android-compiler-plugin/testData/android/converter/simple/noIds/layout.kt @@ -0,0 +1,8 @@ +package kotlinx.android.synthetic.layout + +import android.app.Activity +import android.app.Fragment +import android.view.View +import android.widget.* +import kotlin.internal.flexible.ft + diff --git a/plugins/android-compiler-plugin/testData/android/converter/simple/noIds/layout1.kt b/plugins/android-compiler-plugin/testData/android/converter/simple/noIds/layout1.kt new file mode 100644 index 00000000000..7d00b0d64d5 --- /dev/null +++ b/plugins/android-compiler-plugin/testData/android/converter/simple/noIds/layout1.kt @@ -0,0 +1,8 @@ +package kotlinx.android.synthetic.layout.view + +import android.app.Activity +import android.app.Fragment +import android.view.View +import android.widget.* +import kotlin.internal.flexible.ft +