Solucionar error Could not resolve project :react-native-iap al generar build dev con la librería react-native-iap en React Native de compras in APP

Tiempo de lectura: 3 minutos

Para solucionar el error Could not resolve project :react-native-iap al generar un build de desarrollo usando la librería react-native-iap tendremos que hacer lo siguiente:

Al generar este build, se puede generar para la tienda de aplicaciones de Amazon o la de Google.

Si no seleccionamos ninguna tienda nos aparecerá el siguiente error:

[stderr] FAILURE: Build failed with an exception.

[stderr] * What went wrong:

[stderr] Could not determine the dependencies of task ':app:mergeDebugAssets'.

[stderr] > Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.

[stderr]    > Could not resolve project :react-native-iap.

[stderr]      Required by:

[stderr]          project :app

[stderr]       > The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'. However we cannot choose between the following variants of project :react-native-iap:

[stderr]           - amazonDebugRuntimeElements

[stderr]           - playDebugRuntimeElements

[stderr]         All of them match the consumer attributes:

[stderr]           - Variant 'amazonDebugRuntimeElements' capability QuieroLibros:react-native-iap:unspecified declares a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':

[stderr]               - Unmatched attributes:

[stderr]                   - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'amazonDebug' but the consumer didn't ask for it

[stderr]                   - Provides a library but the consumer didn't ask for it

[stderr]                   - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it

[stderr]                   - Provides attribute 'store' with value 'amazon' but the consumer didn't ask for it

[stderr]           - Variant 'playDebugRuntimeElements' capability QuieroLibros:react-native-iap:unspecified declares a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':

[stderr]               - Unmatched attributes:

[stderr]                   - Provides attribute 'com.android.build.gradle.internal.attributes.VariantAttr' with value 'playDebug' but the consumer didn't ask for it

[stderr]                   - Provides a library but the consumer didn't ask for it

[stderr]                   - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it

[stderr]                   - Provides attribute 'store' with value 'play' but the consumer didn't ask for it

[stderr]         The following variants were also considered but didn't match the requested attributes:

[stderr]           - Variant 'amazonDebugApiElements' capability QuieroLibros:react-native-iap:unspecified declares a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':

[stderr]               - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component

[stderr]           - Variant 'amazonReleaseApiElements' capability QuieroLibros:react-native-iap:unspecified declares a component, preferably optimized for Android:

[stderr]               - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'

[stderr]           - Variant 'amazonReleaseRuntimeElements' capability QuieroLibros:react-native-iap:unspecified declares a runtime of a component, preferably optimized for Android:

[stderr]               - 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'

[stderr]           - Variant 'playDebugApiElements' capability QuieroLibros:react-native-iap:unspecified declares a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':

[stderr]               - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component

[stderr]           - Variant 'playReleaseApiElements' capability QuieroLibros:react-native-iap:unspecified declares a component, preferably optimized for Android:

[stderr]               - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'

[stderr]           - Variant 'playReleaseRuntimeElements' capability QuieroLibros:react-native-iap:unspecified declares a runtime of a component, preferably optimized for Android:

[stderr]               - 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'

[stderr] * Try:

[stderr] > Run with --stacktrace option to get the stack trace.

[stderr] > Run with --info or --debug option to get more log output.

[stderr] > Run with --scan to get full insights.

[stderr] * Get more help at https://help.gradle.org

[stderr] BUILD FAILED in 3m 1s

Para solucionar el error, tenemos que ir a la carpeta Android de nuestro proyecto. Si no la tienes generada, aquí te enseño cómo generarla (https://devcodelight.com/generar-carpetas-de-codigo-nativo-android-ios-en-react-native-con-expo)

Ahora vamos a android>app>build.gradle y añadimos esta línea dentro de defaultConfig

 missingDimensionStrategy 'store', 'play'

Quedando de esta forma:

defaultConfig {
        applicationId 'app.example'
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0.0"
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

        if (isNewArchitectureEnabled()) {
            // We configure the NDK build only if you decide to opt-in for the New Architecture.
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_PLATFORM=android-21",
                        "APP_STL=c++_shared",
                        "NDK_TOOLCHAIN_VERSION=clang",
                        "GENERATED_SRC_DIR=$buildDir/generated/source",
                        "PROJECT_BUILD_DIR=$buildDir",
                        "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
                        "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
                    cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
                    cppFlags "-std=c++17"
                    // Make sure this target name is the same you specify inside the
                    // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
                    targets "app_appmodules"

                    // Fix for windows limit on number of character in file paths and in command lines
                    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                        arguments "NDK_APP_SHORT_COMMANDS=true"
                    }
                }
            }
            if (!enableSeparateBuildPerCPUArchitecture) {
                ndk {
                    abiFilters (*reactNativeArchitectures())
                }
            }
        }
        missingDimensionStrategy 'store', 'play'
    }

Y ya podemos generar de nuevo el build de desarrollo sin error.

1 comentario en «Solucionar error Could not resolve project :react-native-iap al generar build dev con la librería react-native-iap en React Native de compras in APP»

Deja un comentario