Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not annotate with R constants #142

Open
Pomis opened this issue Aug 8, 2018 · 7 comments
Open

Can not annotate with R constants #142

Pomis opened this issue Aug 8, 2018 · 7 comments

Comments

@Pomis
Copy link

Pomis commented Aug 8, 2018

Having strange bug:
Trying to use it like this

@Layout(R.layout.section_item)
class SectionPlaceholder(private val section : Section) {

    @View(R.id.title_textView)
    lateinit var tvTitle: TextView

    @View(R.id.content_textView)
    lateinit var tvContent: TextView

    @Resolve
    fun onResolve() {
        tvTitle.text = section.title
        tvContent.text = section.content
    }
}

But Studio underlines all R.layout/R.id usages and says that An annotation argument must be a compile-time constant. If I try to compile, I get:

 error: incompatible types: <null> cannot be converted to int
@com.mindorks.placeholderview.annotations.Layout(value = null)
                                                         ^

If I use generated constants it fails with runtime exception (res not found)

@Layout(0x7f0f0023)
class SectionPlaceholder(private val section : Section) {

    @View(0x7f0c0071)
    lateinit var tvTitle: TextView

    @View(0x7f0c0020)
    lateinit var tvContent: TextView

    @Resolve
    fun onResolve() {
        tvTitle.text = section.title
        tvContent.text = section.content
    }
}

Used versions:

implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.mindorks.android:placeholderview:1.0.3'
kapt 'com.mindorks.android:placeholderview-compiler:1.0.3'

If I use old version (0.7.3) I have the same issue
Used plugins:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

kotlin version: 1.2.51. Everything works with usual RecyclerView

@dnnyg33
Copy link

dnnyg33 commented Oct 9, 2018

did you ever get this working? i'm surprised no one else has mentioned this issue since it immediately happened when i tried to use the project.

@Pomis
Copy link
Author

Pomis commented Oct 10, 2018

No I decided to use vanilla RecyclerView in that project. Maybe issue was caused by multi module architechture, I don't know

@thphuoc
Copy link

thphuoc commented May 14, 2019

I have the same issue

@jas10022
Copy link

has anyone fixed this issue yet?

@thphuoc
Copy link

thphuoc commented Jul 24, 2019

has anyone fixed this issue yet?

Cannot use an annotation in library module to bind to a resource in app module. Because, All of library will be build and process annotation before build app module. So that, the resource id always is 0.
Another workaround:
Step 1: Disable all of libraries that poiting to resource: Butterknife, PlaceHolderView,...
Step 2: Build app module and copy R.java to the same package name in library module
Step 3: Reenable above libraries and then rebuild

@CloseFile
Copy link

CloseFile commented Sep 20, 2020

has anyone fixed this issue yet?

Cannot use an annotation in library module to bind to a resource in app module. Because, All of library will be build and process annotation before build app module. So that, the resource id always is 0.
Another workaround:
Step 1: Disable all of libraries that poiting to resource: Butterknife, PlaceHolderView,...
Step 2: Build app module and copy R.java to the same package name in library module
Step 3: Reenable above libraries and then rebuild

Thank you sir. This method work for me.
But AS now not show R.java. Need decompile apk and get R.java file.
And after some changes in res files AS change some id rebuild and will be crashed (

@CloseFile
Copy link

Found a working solution. Change module lib to dynamic future module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants