Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
As a workaround, have you tried the butterknife-gradle-plugin and using R2.layouts with your annotations?
https://github.com/JakeWharton/butterknife#library-projects
This will generate final IDs that you can use in your @ContentView annotation.
This will generate final IDs that you can use in your @ContentView annotation.
ja...@gmail.com <ja...@gmail.com> #3
R2 requires special handling for use by an annotation processor only. It's not a direct replacement for R as its value is effectively opaque.
ub...@gmail.com <ub...@gmail.com> #4
As #3 suggests, the "workaround" from #2 does not actually seem to work. Resources$NotFoundException
ja...@gmail.com <ja...@gmail.com> #5
I would advocate for this annotations removal if it's still in alpha.
ub...@gmail.com <ub...@gmail.com> #6
From my perspective a more forward-looking solution would be to conceive a way to make resource IDs final again. In a modularized world, having them be non-final leads to nothing but problems. It was a lesser problem back when they were made non-final originally (somewhere in Jelly Bean I believe).
ja...@gmail.com <ja...@gmail.com> #7
I'd rather eliminate the need to have anyone use an R.layout or R.id reference. You don't care about final IDs when you never touch them directly. Layout XMLs are a schema and we should treat them as such by generating interaction types that abstract the underlying mechanics.
il...@google.com <il...@google.com>
al...@google.com <al...@google.com> #8
Given that a) we intended to lock down annotation APIs about two weeks ago so that we could finalize betas and b) this API surface seems to need further discussion, I'm with #5. Please remove this API and re-add for further discussion in the next feature cycle (about four weeks from now).
se...@google.com <se...@google.com> #9
There is aosp/931676 inflight, that doesn't have this issue, but need to check if tools team can create integration with it, it looks good.
ap...@google.com <ap...@google.com> #10
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 2f634eec2143acd6a4ea19a375a6e3877cdcc2ed
Author: Ian Lake <ilake@google.com>
Date: Tue Mar 19 10:14:07 2019
Convert @ContentView to constructor annotation
As layout IDs are non-final in library modules
(and in the future, app modules), change
@ContentView to only be a marker annotation for
a constructor which developers can call with
a specific layout ID.
Fixes: 128352521
Fixes: 127531658
Test: updated tests
Change-Id: I15e2edee8cbd68180991f89fbc3b04e12c961ede
M activity/api/1.0.0-alpha06.txt
M activity/api/current.txt
M activity/src/androidTest/java/androidx/activity/ContentViewTest.kt
M activity/src/main/java/androidx/activity/ComponentActivity.java
M annotations/api/1.1.0-beta01.txt
M annotations/api/current.txt
M annotations/src/main/java/androidx/annotation/ContentView.java
M appcompat/api/1.1.0-alpha04.txt
M appcompat/api/current.txt
M appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
M fragment/api/1.1.0-alpha06.txt
M fragment/api/current.txt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentFactoryTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentTransactionTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentViewTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/NestedInflatedFragmentTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/StrictFragment.kt
M fragment/src/androidTest/java/androidx/fragment/app/StrictViewFragment.kt
M fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.kt
M fragment/src/androidTest/java/androidx/fragment/app/test/LoaderActivity.kt
M fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
M testutils/src/main/java/androidx/testutils/RecreatedActivity.kt
https://android-review.googlesource.com/931676
https://goto.google.com/android-sha1/2f634eec2143acd6a4ea19a375a6e3877cdcc2ed
Branch: androidx-master-dev
commit 2f634eec2143acd6a4ea19a375a6e3877cdcc2ed
Author: Ian Lake <ilake@google.com>
Date: Tue Mar 19 10:14:07 2019
Convert @ContentView to constructor annotation
As layout IDs are non-final in library modules
(and in the future, app modules), change
@ContentView to only be a marker annotation for
a constructor which developers can call with
a specific layout ID.
Fixes: 128352521
Fixes: 127531658
Test: updated tests
Change-Id: I15e2edee8cbd68180991f89fbc3b04e12c961ede
M activity/api/1.0.0-alpha06.txt
M activity/api/current.txt
M activity/src/androidTest/java/androidx/activity/ContentViewTest.kt
M activity/src/main/java/androidx/activity/ComponentActivity.java
M annotations/api/1.1.0-beta01.txt
M annotations/api/current.txt
M annotations/src/main/java/androidx/annotation/ContentView.java
M appcompat/api/1.1.0-alpha04.txt
M appcompat/api/current.txt
M appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
M fragment/api/1.1.0-alpha06.txt
M fragment/api/current.txt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentFactoryTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentTransactionTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/FragmentViewTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/NestedInflatedFragmentTest.kt
M fragment/src/androidTest/java/androidx/fragment/app/StrictFragment.kt
M fragment/src/androidTest/java/androidx/fragment/app/StrictViewFragment.kt
M fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.kt
M fragment/src/androidTest/java/androidx/fragment/app/test/LoaderActivity.kt
M fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
M testutils/src/main/java/androidx/testutils/RecreatedActivity.kt
il...@google.com <il...@google.com> #11
We've changed how @ContentView functions. The previous form of:
@ContentView(R.layout.main)
class MainFragment : Fragment() {
}
becomes
class MainFragment : Fragment(R.layout.main) {
}
While the default FragmentFactory (and AppComponentFactory for Activities on API 28+) still require a no-argument constructor, Fragment and ComponentActivity/FragmentActivity/AppCompatActivity allow your no-argument constructor or custom constructor to call up to a second constructor which takes a @LayoutRes int of the layout you want to inflate. That second constructor is annotated with @ContentView and will be used for future Tools integrations.
@ContentView(R.layout.main)
class MainFragment : Fragment() {
}
becomes
class MainFragment : Fragment(R.layout.main) {
}
While the default FragmentFactory (and AppComponentFactory for Activities on API 28+) still require a no-argument constructor, Fragment and ComponentActivity/FragmentActivity/AppCompatActivity allow your no-argument constructor or custom constructor to call up to a second constructor which takes a @LayoutRes int of the layout you want to inflate. That second constructor is annotated with @ContentView and will be used for future Tools integrations.
zh...@gmail.com <zh...@gmail.com> #12
Layout IDs will become non-usable in annotations, in application modules?
------
Is it to deliberately kill code such as:
https://github.com/square/mortar/blob/d7bb8e5b5dd773376d940319a49bce9bf7c1058c/mortar-sample/src/main/java/com/example/mortar/screen/ChatListScreen.java#L33
and
https://github.com/lyft/scoop/blob/8d8e499bf3e6399676d314a18094a99a57b99a46/scoop-basics/src/main/java/com/example/scoop/basics/ui/layoutsample/screen/LayoutScreen.java#L10
?
------
Is it to deliberately kill code such as:
and
?
il...@google.com <il...@google.com> #13
For discussion on non-final IDs in app modules and why the Tools team is considering it, see the section on resource namespacing part of the "What's New With the Android Gradle Plugin" talk from AndroidDevSummit: https://www.youtube.com/watch?v=GlwvVJNWlWg&t=1318
ta...@gmail.com <ta...@gmail.com> #14
I've seen in recent changelog that giving layout in constructors is also supported in AppCompatActivity. Is this something supported in older API levels?
il...@google.com <il...@google.com> #15
Re #14 as per the Javadoc: https://developer.android.com/reference/androidx/appcompat/app/AppCompatActivity?hl=en#AppCompatActivity(int)
"This should generally be called from your constructor that takes no parameters, as is required for API 27 and lower or when using the default AppComponentFactory."
"This should generally be called from your constructor that takes no parameters, as is required for API 27 and lower or when using the default AppComponentFactory."
Description
Version used: Version 1.0.0-alpha04
Since `R.layout` is non-final in library projects, we can't use the `@ContentView` annotation.