appodeal / Appodeal-Flutter-Plugin

Official Flutter Plugin that adds Appodeal SDK support to your Flutter application.
https://pub.dev/packages/stack_appodeal_flutter
Apache License 2.0
18 stars 3 forks source link

Build crashes when trying to exclude admob #56

Closed ctotreeapp closed 6 months ago

ctotreeapp commented 6 months ago

Steps to Reproduce

pubspec.yaml stack_appodeal_flutter: ^3.2.0-beta.3

app/build.gradle

    implementation ('com.appodeal.ads:sdk:3.2.0.1-beta.2') {
        exclude group: 'com.appodeal.ads.sdk.networks', module: 'admob'
    }

getting error

E/AndroidRuntime(13575): FATAL EXCEPTION: main
E/AndroidRuntime(13575): Process: com.thetreeapp.thetreeapp, PID: 13575
E/AndroidRuntime(13575): java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
E/AndroidRuntime(13575): 
E/AndroidRuntime(13575): ******************************************************************************
E/AndroidRuntime(13575): * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
E/AndroidRuntime(13575): * should follow the instructions here:                                       *
E/AndroidRuntime(13575): * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
E/AndroidRuntime(13575): * to add a valid App ID inside the AndroidManifest.                          *
E/AndroidRuntime(13575): * Google Ad Manager publishers should follow instructions here:              *
E/AndroidRuntime(13575): * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
E/AndroidRuntime(13575): ******************************************************************************
da2gl commented 6 months ago

@ctotreeapp Hello. Please use this code snippet to exclude Google Admob from your build:

implementation('com.appodeal.ads:sdk:3.2.0.1-beta.2') {
    exclude group: "com.appodeal.ads.sdk.networks", module: "admob"
    exclude group: "io.bidmachine", module: "ads.networks.notsy"
    exclude group: "org.bidon", module: "admob-adapter"
    exclude group: "com.google.android.gms", module: "play-services-ads"
}

Also for faster resolution of the issues, write to us in support in the chat directly in your personal Appodeal account or contact by email support@appodeal.com.

Thank you.

ctotreeapp commented 6 months ago

Thanks, tried this code snippet, still getting

java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: The Google Mobile Ads SDK was initialized incorrectly.

da2gl commented 6 months ago

@ctotreeapp Hello. Can you attach the full build.gradle file?

ctotreeapp commented 6 months ago

app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 33

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.thetreeapp.thetreeapp"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    google()
    mavenCentral()
}

flutter {
    source '../..'
}

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.guava:guava:29.0-android'

    // for using Adjust
    // implementation 'com.google.android.gms:play-services-analytics:16.0.4'
    implementation 'com.android.installreferrer:installreferrer:2.2'

    implementation('com.appodeal.ads:sdk:3.2.0.+') {
        exclude group: "com.appodeal.ads.sdk.networks", module: "admob"
        exclude group: "io.bidmachine", module: "ads.networks.notsy"
        exclude group: "org.bidon", module: "admob-adapter"
        exclude group: "com.google.android.gms", module: "play-services-ads"
    }

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

build.gradle

buildscript {
    ext.kotlin_version = "1.7.10"
    repositories {
        google()
        jcenter()
    }

    dependencies {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
        }
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://artifactory.appodeal.com/appodeal" }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}
mikeSD2 commented 6 months ago

Same problem. Сode snippet didn't help me too (╯ ° □ °) ╯ ┻━┻. Guess its bug...

mikeSD2 commented 6 months ago

@ctotreeapp Hello. Can you attach the full build.gradle file?

help

mikeSD2 commented 6 months ago

app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 33

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.thetreeapp.thetreeapp"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    google()
    mavenCentral()
}

flutter {
    source '../..'
}

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.annotation:annotation:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.guava:guava:29.0-android'

    // for using Adjust
    // implementation 'com.google.android.gms:play-services-analytics:16.0.4'
    implementation 'com.android.installreferrer:installreferrer:2.2'

    implementation('com.appodeal.ads:sdk:3.2.0.+') {
        exclude group: "com.appodeal.ads.sdk.networks", module: "admob"
        exclude group: "io.bidmachine", module: "ads.networks.notsy"
        exclude group: "org.bidon", module: "admob-adapter"
        exclude group: "com.google.android.gms", module: "play-services-ads"
    }

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

build.gradle

buildscript {
    ext.kotlin_version = "1.7.10"
    repositories {
        google()
        jcenter()
    }

    dependencies {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
        }
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://artifactory.appodeal.com/appodeal" }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

I tried appodeal version 3.1.3 and it's working. You can use it while the new version is being fixed. ))

da2gl commented 6 months ago

@mikeSD2 @ctotreeapp Thanks for yours snippets. We are looking for a solution.

da2gl commented 6 months ago

@mikeSD2 @ctotreeapp Hi, we found fast way to exclude Admob from your android project:

  1. Open your flutter android module as android project (Tools -> Flutter -> Open Android module in Android Studio or from File section)
  2. Go to build.gradle for :stack_appodeal_flutter module and comment or remove next lines:
dependencies {
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:$kotlin_version"))
    // Appodeal SDK 3.2.0.+
    implementation 'com.appodeal.ads.sdk:core:3.2.0'
    implementation 'com.appodeal.ads.sdk.networks:iab:3.2.0.+'
//    implementation 'com.appodeal.ads.sdk.networks:bidon:3.2.0.+'
//    implementation 'com.appodeal.ads.sdk.networks:bidmachine:3.2.0.+'
    implementation 'com.appodeal.ads.sdk.services:sentry_analytics:3.2.0.+'
}
Снимок экрана 2023-12-28 в 12 26 59
  1. Go to build.gradle for :app module and add next dependencies:
dependencies {
    implementation('com.appodeal.ads:sdk:3.2.0.+') {
        // ad networks
        exclude group: "com.appodeal.ads.sdk.networks", module: "admob"
        exclude group: "com.appodeal.ads.sdk.networks", module: "bidon"
        exclude group: "com.appodeal.ads.sdk.networks", module: "bigo_ads"
        exclude group: "com.appodeal.ads.sdk.networks", module: "bidmachine"
        // services
        exclude group: 'com.appodeal.ads.sdk.services', module: 'adjust'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'appsflyer'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'firebase'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'facebook_analytics'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'stack_analytics'
    }
}
Снимок экрана 2023-12-28 в 12 29 59
  1. Done

In the next release we will simplify the core library dependencies so that Admob can be easily excluded. Thanks for the issue.

ctotreeapp commented 6 months ago

@da2gl You suggested to exclude bidmachine, but we need this one. What we want to exclude is AdMob. Are Bidmachine and Admob modules connected somehow?

AntonZarytski commented 6 months ago

@ctotreeapp Hi! The Bidmachine module contains a dependency on play-services-ads like Admob, Bidon and BigoAds. If you plan to use Bidmachine, you can use this dependency structure:

implementation('com.appodeal.ads:sdk:3.2.0.+') {
        exclude group: 'com.google.android.gms', module: 'play-services-ads'
        // ad networks
        exclude group: "com.appodeal.ads.sdk.networks", module: "admob"
        exclude group: "com.appodeal.ads.sdk.networks", module: "bigo_ads"
        // services
        exclude group: 'com.appodeal.ads.sdk.services', module: 'adjust'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'appsflyer'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'firebase'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'facebook_analytics'
        exclude group: 'com.appodeal.ads.sdk.services', module: 'stack_analytics'
    }

In this case you will have both Bidmachine and Bidon working (except Admob, which is also present in these modules). Please note that all services necessary for user acquisition and attribution will be disabled.

da2gl commented 6 months ago

Hi! We have prepared a release where we have simplified the plugin core dependency logic and improve our documentation about Admob Configuration

60