Skip to content

Android template generates invalid Kotlin in $$androidCxxLibName$$Package.kt #529

Description

@qalqi

Describe the bug

The Android template generates an invalid Kotlin file for $$androidCxxLibName$$Package.kt.

The file has a .kt extension but mixes Java and Kotlin syntax, causing the generated project to fail compilation.

To Reproduce

  1. Generate a new Nitro module using create-nitro-module.
  2. Build the Android project.
  3. The generated $$androidCxxLibName$$Package.kt fails to compile.

Generated code:

package com.$$androidNamespace$$;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.BaseReactPackage;
import com.margelo.nitro.$$androidNamespace$$.$$androidCxxLibName$$OnLoad;

public class $$androidCxxLibName$$Package : BaseReactPackage() {
  override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null

  override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
    ReactModuleInfoProvider { emptyMap() }

  companion object {
    init {
      $$androidCxxLibName$$OnLoad.initializeNative();
    }
  }
}

Expected behavior

The template should generate valid Kotlin.

For example:

package com.$$androidNamespace$$

import com.facebook.react.BaseReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.model.ReactModuleInfoProvider
import com.margelo.nitro.$$androidNamespace$$.$$androidCxxLibName$$OnLoad

class $$androidCxxLibName$$Package : BaseReactPackage() {
  override fun getModule(
    name: String,
    reactContext: ReactApplicationContext,
  ): NativeModule? = null

  override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
    ReactModuleInfoProvider { emptyMap() }

  companion object {
    init {
      $$androidCxxLibName$$OnLoad.initializeNative()
    }
  }
}

Additional context

The generated template appears to mix Java and Kotlin syntax:

  • public class is Java syntax and is invalid in Kotlin.
  • The file is emitted with a .kt extension.
  • Semicolons are acceptable in Kotlin, but the class declaration is not.

This looks like a template generation issue rather than a Kotlin compiler issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions