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

Unresolved reference: R #7

Closed
tomriddle7 opened this issue Nov 17, 2020 · 12 comments
Closed

Unresolved reference: R #7

tomriddle7 opened this issue Nov 17, 2020 · 12 comments
Labels
Android Android Home Screen Widgets

Comments

@tomriddle7
Copy link

I copied files in kotlin/es/antonborri/home_widget_example and launched main.dart but it says Unresolved reference: R

I think that this line makes error.

val views = RemoteViews(context.packageName, R.layout.example_layout).apply {

Do I have to import R to my project?

@ABausG
Copy link
Owner

ABausG commented Nov 17, 2020

Did you create the Layout File?
I would advise to do the actual Android Programming in Android Studio as that will provide you with the best code suggestions

@tomriddle7
Copy link
Author

Sure. I created same layout file as in example. And I created Widget Configuration and WidgetReceiver.

@ABausG
Copy link
Owner

ABausG commented Nov 17, 2020

Does the issue persist after building it? Could you link me the code so I can take a look at it?

@ABausG ABausG added the Android Android Home Screen Widgets label Nov 17, 2020
@tomriddle7
Copy link
Author

https://github.com/tomriddle7/Dotgasaki
this is my project.

@leonardocustodio
Copy link
Contributor

@tomriddle7 the problem about your project is that you created a kotlin/es/antonborri/home_widget_example directory.
This part of the example "HomeWidgetExampleProvider.kt" should be in your home directory so for your project, it should be in: kotlin/com/tomriddle7/dotgasaki/

Regards,

@tomriddle7
Copy link
Author

@leonardocustodio It was very useful tip. It works well. Thanks.

@lucasjinreal
Copy link

@leonardocustodio I got same error, but I am not create such wrong package name directories, Still says can not resolve R.

image

any idea?

@lucasjinreal
Copy link

image

How do I make these red error gone? I already added the lib dependencies in pubspec.yml

@petrnymsa
Copy link

@jinfagang Did you managed to solve this?

@ABausG
Copy link
Owner

ABausG commented Feb 16, 2022

I think this is an issue with how the android framework is loaded. It should also appear in files like the MainActivity.kt that are created by Flutter itself.

Do you have AndroidStudio installed? Could you try (in vscode/intellij/android studio) right click on the android/ folder and say flutter -> Open Android Module in Android Studio

@ABausG
Copy link
Owner

ABausG commented Feb 16, 2022

@jinfagang @petrnymsa do you receive actual runtime errors or is this more or less only when viewing the files in the IDE?

@petrnymsa
Copy link

@ABausG Acutally runtime errors, but I've managed to in the end compile it BUT (and I know this should belong to separate issue probably).

I think whole "example" is wrong? Because there is no simply setOnClickPendingIntent as standalone method, instead I've found this solution:

 val views = RemoteViews(context.packageName, R.layout.widget_layout)
        val pendingIntent = HomeWidgetLaunchIntent.getActivity(context, MainActivity::class.java)
        views.setOnClickPendingIntent(R.id.widget_base_layout, pendingIntent)
        ```
        
        Which unfortunately does not work too... 

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

No branches or pull requests

5 participants