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

Unable to use config in the android/build.gradle file #814

Open
lpatrun opened this issue Sep 27, 2024 · 1 comment
Open

Unable to use config in the android/build.gradle file #814

lpatrun opened this issue Sep 27, 2024 · 1 comment

Comments

@lpatrun
Copy link

lpatrun commented Sep 27, 2024

Hello, I am implementing this lib and for my project, I also have to use it in android/build.gradle. I have tried the solution from issue #674 but first I got this error:

Could not find method android() for arguments [dotenv_5v1ei16f50d47056n9s7kjkve$_run_closure1@6a407e85] on root project 'AvarTtoGO' of type org.gradle.api.Project

Then I added:

apply plugin: "com.android.application"

and got:

com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle

And after I add

android {
    compileSdkVersion = 33
}

I get

Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.

I would appreciate help.

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

android {
    compileSdkVersion = 33
}

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 22
        compileSdkVersion = 33
        targetSdkVersion = 33
        ndkVersion = "21.4.7075529"
        androidXCore = "1.7.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.1")
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
    }
}

allprojects {
    repositories {
        exclusiveContent {
            filter {
                 includeGroup "com.facebook.react"
            }
            forRepository {
                 maven {
                    url "$rootDir/../node_modules/react-native/android"
                 }
            }
        } 
        mavenCentral()
        mavenLocal()
        maven {
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }

        if (project.env.get("APP_CONFIG") == "development") {
            maven {

            }
        }
    }
}


@amrfarid140
Copy link

You need to add apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" in android/app/build.gradle not the root android/build.gradle.

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

No branches or pull requests

2 participants