-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Android] Fix issue where CODE_PUSH_APK_BUILD_TIME resource was not generating w/ AGP 4.2+ #2337
Conversation
@chrisglein @jedashford @andreidubov @alexandergoncharov-zz |
@ddikodroid thanks for the PR! We have couple of question regarding it:
|
i'm not creating the PR, i just help the author to be noticed🙌🏻 hope it will get merged soon |
Moving the I am using react native 0.69.5 (ejected from expo 46)
|
Good catch! I've fixed this in 3733a6b. |
Thanks that is working |
@appcenter-fte Can you please check this one ? |
Seriously this issue is still open without the attention from the Microsoft Team? We are having the same problem in Android... |
Why isn't this merged yet?? |
Have you planned to publish it in a new version ? |
thanks, its worked for me |
@hugohow The release with this fix included is published. |
I am still facing this issue even after updating codepush to 7.1.0
configurations: |
@Abbondanzo @thewulf7 "react": "18.2.0", Gradle 8.0.1Build time: 2023-02-17 20:09:48 UTC Kotlin: 1.8.10 |
Which workaround are you using? The fix should be available in every version of CodePush greater than 7.1.0 (if you're following the setup instructions for Android here) |
Hi, I have used the below in
I am using Multi-Deployment Testing and problem was only with "secondary" deployment releaseStaging
|
Thanks..! That worked for me, but is this a mature approach? or do we have some other approaches too? |
@rmhn10 Hi, What React Native Code Push version do you use? |
7.0.4 |
@rmhn10 Great! |
Temporary workaround
Until this is merged, you can do the following to work around the issue: in the
build.gradle
file located in your app module (i.e.my-project/android/app/build.gradle
, not the one in the directory up), add the following lines at the end of the file to replicate the fix:There's nothing wrong with generating this resource twice, Android will let you know if it detects both. To confirm that the file has been generated, navigate to
my-project/android/app/build/generated/res/resValues/(debug|release)/values/gradleResValues.xml
and you should see theCODE_PUSH_APK_BUILD_TIME
resource value in there.PR Description
Relevant issues:
My build setup:
We've got a very jank patch of CodePush running, but the problem lies in resource generation. Nevertheless, here's where we're at:
[email protected]
[email protected]
com.android.tools.build:gradle:7.2.1
Motivation:
React Native versions 0.66.0 and up are encouraged to use Android Gradle Plugin 4.2+, so almost certainly anyone who comes across this library will run into some issue regarding this resource value not generating.
Context:
The provided suggestion in almost every one of these issues was to move the
resValue
call to evaluation time rather than having it run after evaluation time. And this is an important distinction; I'll try to explain why here.Somewhere around Android Gradle Plugin release 4.2 all the way thru to today, the internals for the
ComponentCreationConfig
that AGP'sGenerateResValues
task relies on was changed. I spent a good several hours poking around with a debugger to see what was called, and when. TheresValue
function of theBaseFlavor
, which stores a mapping of resource keys to their respective values, is correctly called for all resource values. This includes the CodePush SDK built time resource value being set here. However, what ended up changing was that halfway between configuration, the map was read from theVariantDSLInfo
class and made immutable as part of the task's inputs. Conveniently, any future calls to set new resource values would still be written to the flavor's map internally but would be ignored since the task'sMapProperty
provider does not change.As a result, AGP does not honor any
resValue
calls after evaluation is complete. While it should be throwing an error as it's already doing if you try to configure via a library variant, it is far less strict and will not throw an error if you try to configure from, say a build type or flavor. TheGenerateResValues
task reaches out to the variant for its resource values, and theVariantImpl
reaches over to theVariantDSLInfoImpl
which collects from theBaseConfigImpl
. After it does all this, it marks the map of resource values immutable only inside of theVariantImpl
but we're free to make additions that don't get honored from any futher in that chain.All of this is to say: TL;DR there are no exceptions thrown by AGP despite the fact that there should be. Either the task should lazily ask the property provider to produce the mapping upon execution, or the various configuration implementations should throw exceptions if you try to modify them. Indeed some do, but not in this case.
Alternatives:
There are a couple ways around this change, but I went with the change that felt like it made the most sense.
android.buildTypes.each
withandroid.defaultConfig
gradle.afterProject
closuregradle.afterEvaluate
closer. In fact, any closure that uses the word evaluated with the word after does not work