3

I want to refactor my code and use Kotlin instead. I used Android Annotations in my project and most of my classes are auto-generated (with underscores). So I tried to use some of my beans in a Kotlin Activity and I get "Unresolved reference "..... _"

This is my code:

import com.zeekit.client.android.service.AppInitializer
import com.zeekit.client.android.service.AppInitializer_
import com.zeekit.client.android.service.NotificationsManager
import com.zeekit.client.android.service.NotificationsManager_

class MainActivity : NavigationActivity() {

    private val appInitializer: AppInitializer = AppInitializer_.getInstance_(applicationContext)
    private val notificationsManager: NotificationsManager = NotificationsManager_.getInstance_(applicationContext)

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
        setContentView(R.layout.activity_main)
        if (appInitializer.isValidVersion == false) {
            showUpdatePopup()
            return
        }
    }

Error:

activity\MainActivity.kt: (10, 42): Unresolved reference: AppInitializer_
activity\MainActivity.kt: (12, 42): Unresolved reference: NotificationsManager_
activity\MainActivity.kt: (16, 50): Unresolved reference: AppInitializer_
activity\MainActivity.kt: (17, 62): Unresolved reference: NotificationsManager_
Zach Bublil
  • 857
  • 10
  • 28
  • It's an issue with creating those classes. Check build log. Give up android-annotations - It causes more problems than benefits. – 3mpty Aug 22 '18 at 11:15
  • Well, I can't agree with you. Passing arguments to fragments looks much harder in Kotlin. The build method for any generated fragment save me that "newInstance" method in every fragment – Zach Bublil Aug 22 '18 at 11:21
  • When you have more than one code generating dependency it's getting harder to track compile time issues, for example dagger2 and android annotations. Also if you will want remove (bug or any other reason) android annotations dependency in future it will be very hard to do it. Any annotation based library increases build time. `newInstance` is not that hard to implement and you can always use Kotlin features like optional arguments. – 3mpty Aug 22 '18 at 12:09
  • I dunno man. I generally pass a single `@Parcelize data class` as argument and it works fine for me. But if that's not your cup of tea, setting the arguments bundle of a Fragment isn't that hard anyway. – EpicPandaForce Aug 22 '18 at 21:36
  • @ZachBublil did you find how to do it? do you have a solution? share pls. – LunaVulpo Aug 12 '20 at 23:02
  • I just stopped using Android annotations and moved to kotlin :) – Zach Bublil Aug 14 '20 at 10:44

0 Answers0