Orion
Orion

Reputation: 393

Could not get unknown property 'android' for root project 'android' of type org.gradle.api.Project

I tried to add Onesignal as Push Service to an App, but now i get following error after editing the build.gradle file.

ERROR: Could not get unknown property 'android' for root project 'android' of type org.gradle.api.Project.

Can someone tell me how to fix that? It's my first time editing an android project.

Thats my build.gradle(app) file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        applicationId "io.gonative.android.azndpe"
        versionCode 2

        manifestPlaceholders = [manifestApplicationId: "${applicationId}",
                                onesignal_app_id: "APP-ID",
                                onesignal_google_project_number: "REMOTE"]
    }

    signingConfigs {
        release {
            storeFile file("../../release.keystore")
            storePassword "password"
            keyAlias "release"
            keyPassword "password"
        }
        upload {
            storeFile file("../../upload.keystore")
            storePassword "password"
            keyAlias "upload"
            keyPassword "password"
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        releaseApk {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            zipAlignEnabled true
            signingConfig signingConfigs.release
        }
        releaseAppbundle {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            zipAlignEnabled true
            signingConfig signingConfigs.upload
        }
    }

    flavorDimensions "webview"

    productFlavors {
        normal {
            dimension "webview"
        }
    }
}

dependencies {
    implementation 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2'
    implementation 'com.facebook.android:facebook-android-sdk:4.39.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-gcm:12.0.1'
    implementation 'com.google.android.gms:play-services-location:12.0.1'
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
    implementation fileTree(dir: 'libs', include: '*.jar')
    implementation fileTree(dir: 'libs', include: '*.aar')

}

Upvotes: 26

Views: 60465

Answers (4)

Giddy Naya
Giddy Naya

Reputation: 4668

For OP's context

The error Could not get unknown property 'android' for root project 'projectName' of type org.gradle.api.Project. means you applied the onesignal-gradle-plugin to your root build.gradle or android/build.gradle instead of the one in app/build.gradle. Moving this will fix your error.

Line in context

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

See discussion

Edit: For General context

  1. This is a common mistake. Make sure that your android plugins are applied to the build.gradle file which can be found under the apps folder (app/build.gradle) and not mistakenly applied to the one inside your root project directory /build.gradle. If that is the case then moving the line(s) into the app/build.gradle file should fix.

    There can be several plugins but below is a common line in context which can be found at the top of the gradle file:

    apply plugin: 'com.android.application'
    
  2. Check that you have a valid version number of the Android Gradle plugin in your /build.gradle file and no typo in it. See here for latest plugin versions.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:VERSION_NUMBER'
    }
}
  1. Confirm that Offline Mode is turned off for Gradle Sync. See how to.

  2. If the error still persist then Invalidate Cache and Restart android studio.

Upvotes: 44

Jean-Pierre Schnyder
Jean-Pierre Schnyder

Reputation: 1954

This my solution. The problem was due to the fact that I had upgraded java.

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip

enter image description here

Upvotes: 6

adel parsa
adel parsa

Reputation: 454

It was a strange error.
I have 2 systems with identical versions of SDK, flutter, dart even windows and android studio versions.
The project worked fine in the first system but the second system threw this error! It happened to me and I solved it by updating the version of Gradle for the target library.
In my case, I updated the version of Gradle from 3.4.2 to 4.1.1 and remade the project, and the problem was solved!

Edit this file (the library that throws this error): \src\flutter.pub-cache\hosted\pub.dartlang.org\url_launcher_android-6.0.17\android/build.gradle

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
       // classpath 'com.android.tools.build:gradle:3.4.2'
       // changed to
        classpath 'com.android.tools.build:gradle:4.1.1'
    }
}

But I'm trying to find a better solution to this error!

Upvotes: 0

MUHINDO
MUHINDO

Reputation: 1241

if you are using one signal, make sure the following apply plugin like is inside

android/app/build.gradle 

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

not anywhere else

Upvotes: 0

Related Questions