16

I wanted to migrate my existing project to partially use Jetpack compose for it.
So I opened it using Android studio 4.2-canary9 and added a compose activity so that Android studio adds needed configurations needed.

When I tried to run the project it gave me an error:

e: java.lang.AssertionError: Unbound symbols not allowed

Using Run with --stacktrace I have this stacktrace thrown at me:

e: java.lang.AssertionError: Unbound symbols not allowed
    Unbound public symbol for public kotlinx.android.synthetic.main.activity_main/state.<get-state>|-5663767092261428579[0]
    Unbound public symbol for public kotlinx.android.synthetic.main.activity_main/stateContainer.<get-stateContainer>|-4335442114828357571[0]
    Unbound public symbol for public kotlinx.android.synthetic.main.activity_main/list.<get-list>|9139041782698166288[0]
    at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:96)
    at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFiles(JvmBackendFacade.kt:87)
    at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:40)
    at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:616)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:203)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:86)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:346)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:240)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:81)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:601)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1633)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

The first route mentions activity_main which is an activity not made using compose. It refers to Kotlin android extensions which is used to replace findViewById (state is a TextView ID)

Unbound public symbol for public kotlinx.android.synthetic.main.activity_main/state.<get-state>|-5663767092261428579[0]

Here are some configurations:

  • compose: 1.0.0-alpha02 & 1.0.0-alpha04
  • kotlin: 1.4.0 & 1.4.10
  • android-gradle-plugin: 4.2.0-alpha09 & 4.2.0-alpha13
  • kotlin-stdlib: either jdk8 and jdk7

Thanks in advance

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117

4 Answers4

12

I had the same problem. As a workaround, I replaced all Kotlin synthetic with ViewBinding. After I did it everything worked.

ithersta
  • 158
  • 2
  • 13
4

Apparently, this issue has been fixed and will be shipped to Kotlin:1.4.20 (Which is not released at the time)

Google issue tracker reference

Kotlin Pull request

[Update at 27 Nov]

Updating to 1.4.20 leads to another error [Ref]

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
  • composeOptions { kotlinCompilerVersion '1.4.20' kotlinCompilerExtensionVersion '1.0.0-alpha04' } After updating the Kotlin compiler to 1.4.20, I get this error 'could not find org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.20' – Sreeram Sunkara Oct 23 '20 at 01:56
  • 1
    Unfortunately `1.4.20` is not released yet. It's a promise that it will be fixed in that version. Checkout [kotlin releases](https://github.com/JetBrains/kotlin/releases) for detail. – Mahdi-Malv Oct 23 '20 at 14:47
  • this works but `1.4.20` causes this https://youtrack.jetbrains.com/issue/KT-43350. so... – guness Nov 23 '20 at 12:27
  • @guness Yup... Tried `1.4.20` myself. Didn't work. You're right – Mahdi-Malv Nov 24 '20 at 12:45
  • True story, updating to 1.4.20 lead to the above error described by Mahdi-Malv – VasFou Nov 27 '20 at 14:21
1

I had a similar problem when I was migrating a template project. What fixed it for me was deleting some template code that accessed elements that were grabbed by findbyviewid.

stegnerd
  • 1,119
  • 1
  • 17
  • 25
  • Any code in the default views that was created that referenced views directly. For example any code that used findViewById. – stegnerd Oct 12 '20 at 23:41
0

I have to choose the other way around for this case,

composeOptions {
    kotlinCompilerExtensionVersion "1.1.0-beta03"
}

I also have to downgrade the Kotlin version for this.

ext.kotlin_version = "1.5.31"
ext.compose_version = '1.1.1'
Bharat Lalwani
  • 1,277
  • 15
  • 17