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

feat: add expo config plugin #2218

Merged

Conversation

pafry7
Copy link
Contributor

@pafry7 pafry7 commented Jan 26, 2023

Why

Currently, you cannot use react-native-iap with expo (at least on android), because you have to configure build.gradle. Building an android app results in the following error:

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :react-native-iap.
     Required by:
         project :app
      > The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1'. However we cannot choose between the following variants of project :react-native-iap:
          - amazonDebugApiElements
          - playDebugApiElements
        All of them match the consumer attributes:
          - Variant 'amazonDebugApiElements' capability Quikś:react-native-iap:unspecified declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Unmatched attributes:
                  - Provides attribute 'com.android.build.api.attributes.ProductFlavor:store' with value 'amazon' but the consumer didn't ask for it
                  - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'amazonDebug' but the consumer didn't ask for it
                  - Provides a library but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Provides attribute 'store' with value 'amazon' but the consumer didn't ask for it
          - Variant 'playDebugApiElements' capability Quikś:react-native-iap:unspecified declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
              - Unmatched attributes:
                  - Provides attribute 'com.android.build.api.attributes.ProductFlavor:store' with value 'play' but the consumer didn't ask for it
                  - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'playDebug' but the consumer didn't ask for it
                  - Provides a library but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
                  - Provides attribute 'store' with value 'play' but the consumer didn't ask for it
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'amazonReleaseApiElements' capability Quikś:react-native-iap:unspecified declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
          - Variant 'amazonReleaseRuntimeElements' capability Quikś:react-native-iap:unspecified declares a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
          - Variant 'playReleaseApiElements' capability Quikś:react-native-iap:unspecified declares an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
          - Variant 'playReleaseRuntimeElements' capability Quikś:react-native-iap:unspecified declares a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'

How

I've created config plugin that changes the content of both build.gradle files.

TODO

  • add AndroidX support,
  • make sure nothing is missing for the plugin to work properly when published

@pafry7 pafry7 force-pushed the feat/add-expo-config-plugin branch from 5256a2b to 3da0250 Compare January 26, 2023 15:36
@pafry7 pafry7 force-pushed the feat/add-expo-config-plugin branch from 3da0250 to bf5a080 Compare January 26, 2023 18:44
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
missingDimensionStrategy "store", "play"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these variables have some duplication, any thoughts on using a common template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that there is too much of it. In current unit tests implementation, we are passing initial build.gradle (part of it to be precise) to the function and comparing the result with the correct version. This is done 3 times, one for each paymentProvider. We could remove irrelevant lines and leave only lines close to defaultConfig. What do you think?

Comment on lines +104 to +105
versionCode 34
versionName "1.16.2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these arbitrary/ do they matter to the person building an expo app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All files in the fixtures directory are used solely for testing and will only be utilized by a developer writing tests.

}

defaultConfig {
applicationId 'com.test.withIAP'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these be customizable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only a part of some faked build.gradle file to ensure that properties are added correctly in tests. Content is irrelevant. Maybe we should add a comment that explains it?

@andresesfm
Copy link
Collaborator

Thank you for your contribution @pafry7. I added some simple comments/questions. Let me know what you think. Overall great work, thank you for the unit tests too


const pkg = require('../../package.json');

type PaymentProvider = 'Amazon AppStore' | 'both' | 'Play Store';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this naming is okay? I didn't put much effort into it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should be OK, Thank you for your contribution

@andresesfm andresesfm merged commit 4710655 into dooboolab-community:main Jan 30, 2023
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

Successfully merging this pull request may close these issues.

2 participants