web-dev-qa-db-fra.com

Variable BuildConfig. Erreur: impossible de trouver le symbole

Dans le projet j'ai plusieurs flavors, plusieurs buildTypes et plusieurs folders pour les combinaisons

Construire des combinaisons:

 enter image description here

Structure de dossier

 enter image description here

Dans chaque dossier, j'ai Application class + AndroidManifest personnalisé pour enregistrer ce Application class

 enter image description here

Parfois, mais juste parfois la construction échoue avec l'erreur cannot find symbol:

\app\src\main\Java\ru\my\package\app\environment\MyApp.Java:35: error: cannot find symbol
            .core(new CrashlyticsCore.Builder().disabled(!BuildConfig.ANALYTICS).build())

ou App classe indépendante mais la même erreur

\app\src\main\Java\ru\my\package\presentation\presenter\impl\MainPresenterImpl.Java:104: error: cannot find symbol
    if (!BuildConfig.ANALYTICS) return;

Mais la toute prochaine construction pourrait être réussie, donc le flux possible est

  1. Construire (réussi)
  2. Quelques chagnes dans le code
  3. Construire (erreur)
  4. Nouvelle tentative de compilation (réussie) <- sans aucune modification du code

Remarque

  • Ce n'est pas un problème de sync et le cache sync/invalidate n'est pas la solution
  • Ce n'est pas un mauvais problème import

Avertissement: certaines questions ressemblent à celle-ci, mais elles sont différentes, par exemple.

Gradle buildConfigField BuildConfig ne peut pas résoudre le symbole

METTRE &AGRAVE; JOUR

Dépendances Gradle:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation project(path: ':OVSALibrary')
    implementation project(path: ':YaMapProject')
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'com.google.dagger:dagger:2.14.1'
    kapt 'com.google.dagger:dagger-compiler:2.14.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'eu.davidea:flexible-adapter:5.0.0-rc3'
    kapt 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation "com.Android.support:appcompat-v7:$support_lib_version"
    implementation "com.Android.support:design:$support_lib_version"
    implementation "com.Android.support:support-v4:$support_lib_version"
    implementation "com.Android.support:recyclerview-v7:$support_lib_version"
    implementation "com.Android.support:support-emoji:$support_lib_version"
    implementation "com.Android.support:support-emoji-appcompat:$support_lib_version"
    implementation "com.Android.support:support-emoji-bundled:$support_lib_version"
    implementation 'com.Android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
    implementation 'ru.egslava:MaskedEditText:1.0.5'
    implementation 'nl.big-o:liqp:0.7.3'
    implementation 'org.jsoup:jsoup:1.7.2'
    implementation 'me.everything:overscroll-decor-Android:1.0.4'
    implementation 'com.squareup.picasso:picasso:2.6.0-SNAPSHOT'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile ('com.squareup.retrofit2:converter-simplexml:2.3.0') {
        exclude group: 'stax', module: 'stax-api'
        exclude group: 'stax', module: 'stax'
        exclude group: 'xpp3', module: 'xpp3'
    }
    implementation 'com.makeramen:roundedimageview:2.3.0'
    implementation ('com.github.revern:socket.io-client-Java:master-SNAPSHOT') {
        exclude group: 'org.json', module: 'json'
    }
    implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'
    implementation 'com.luckycatlabs:SunriseSunsetCalculator:1.2'
    implementation ('com.github.developer-shivam:Crescento:1.2.1') {
        exclude group: 'com.Android.support', module: 'appcompat-v7'
        exclude group: 'com.Android.support', module: 'palette-v7'
    }
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'
    implementation('com.crashlytics.sdk.Android:crashlytics:2.9.0@aar') {
        transitive = true;
    }
    implementation 'com.Android.support:cardview-v7:27.1.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

    implementation 'com.malinskiy:superrecyclerview:1.1.4'

    // Yandex.Map things
    implementation 'com.yandex.Android:mapkit:3.0.0'

    // Yandex ads. Adfox.
    rcImplementation 'com.yandex.Android:mobmetricalib:3.0.0'
    debugWithAnalyticsImplementation 'com.yandex.Android:mobmetricalib:3.0.0'
    releaseImplementation 'com.yandex.Android:mobmetricalib:3.0.0'
    implementation 'com.yandex.Android:mobileads:2.71'


    // Waiting for https://github.com/SundeepK/CompactCalendarView/pull/287
    // Waiting for https://github.com/SundeepK/CompactCalendarView/pull/288
    implementation 'com.github.dryaz:CompactCalendarView:master-SNAPSHOT'

    // Waiting for https://github.com/opacapp/multiline-collapsingtoolbar/pull/57
    implementation 'com.github.dryaz:multiline-collapsingtoolbar:master-SNAPSHOT'

    implementation 'com.github.clans:fab:1.6.4'

    implementation 'org.greenrobot:eventbus:3.1.1'

    testImplementation "org.robolectric:robolectric:3.8"
    testImplementation 'junit:junit:4.12'
    testImplementation "com.Android.support.test:monitor:1.0.2"
    androidTestImplementation 'com.Android.support.test:runner:1.0.2'
    androidTestImplementation 'com.Android.support.test.espresso:espresso-core:3.0.2'

    // PAY SDK
    implementation(name:'mos-pay-sdk-1.0.9', ext:'aar')
    implementation 'io.card:Android-sdk:5.5.1'
    implementation ('eu.livotov.labs.Android:3DSView:1.1.2@aar') {transitive=true}

    // Android Architecture Components
    implementation "Android.Arch.lifecycle:runtime:$androidArch"
    implementation "Android.Arch.lifecycle:extensions:$androidArch"
    annotationProcessor "Android.Arch.lifecycle:compiler:$androidArch"

    compile 'com.google.firebase:firebase-core:16.0.0'
    compile 'com.google.firebase:firebase-messaging:17.0.0'
}

** UPDATE ** Voici la liste de buildTypes et productFlavors

flavorDimensions("devbeta", "mainmirror")
    productFlavors {
        // Beta API enviroment
        beta {
            dimension = "devbeta"
            buildConfigField "String", "SOCKET_REMOTE_PATH", "\"/api-beta/socket.io\""
        }

        // Dev API enviroment
        dev {
            dimension = "devbeta"
            buildConfigField "String", "SOCKET_REMOTE_PATH", "\"/api-dev/socket.io\""
        }

        // Prod API enviroment
        prod {
            dimension = "devbeta"
            buildConfigField "String", "SOCKET_REMOTE_PATH", "\"/socket.io\""
        }

        mainhost {
            dimension = "mainmirror"
            buildConfigField "String", "CONFIG_REMOTE_HOSTNAME", "\"some.Host.url\""
        }

        mirrorhost {
            dimension = "mainmirror"
            buildConfigField "String", "CONFIG_REMOTE_HOSTNAME", "\"some.Host.url\""
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            buildConfigField "boolean", "ANALYTICS", "false"
            signingConfig signingConfigs.customDebug
            ext.enableCrashlytics = false
            manifestPlaceholders = [
                    firebaseAnalyticsDeactivated: "true",
                    appIcon: "@mipmap/ic_launcher_debug",
            ]
        }

        debugWithAnalytics.initWith(buildTypes.debug)
        debugWithAnalytics {
            ext.betaDistributionGroupAliases = "group-internal"
            ext.betaDistributionReleaseNotes = "$getReleaseNotes"
            ext.enableCrashlytics = true
            buildConfigField "boolean", "ANALYTICS", "true"
            matchingFallbacks = ['debug', 'release']
        }

        debugWithProguard.initWith(buildTypes.debug)
        debugWithProguard {
            minifyEnabled true
            shrinkResources true
            proguardFiles(file('./proguard').listFiles())
            matchingFallbacks = ['release', 'debug']
        }

        // RC build for inner testers that has analytics, signed with debug key.
        rc {
            minifyEnabled true
            shrinkResources true
            proguardFiles(file('./proguard').listFiles())
            buildConfigField "boolean", "ANALYTICS", "true"
            // Fields for fabric beta distribution
            ext.betaDistributionGroupAliases = "group-internal"
            ext.betaDistributionReleaseNotes = "$getReleaseNotes"

            signingConfig signingConfigs.customDebug

            manifestPlaceholders = [
                    firebaseAnalyticsDeactivated: "false",
                    appIcon: "@mipmap/ic_launcher_rc",
            ]
            matchingFallbacks = ['debug', 'release']
        }

        release.initWith(buildTypes.rc)
        release {
            buildConfigField "boolean", "ANALYTICS", "true"
            ext.betaDistributionGroupAliases = "group-customer"
            signingConfig signingConfigs.release
            manifestPlaceholders = [
                    firebaseAnalyticsDeactivated: "false",
                    appIcon: "@mipmap/ic_launcher",
            ]
        }
    }
5
dilix

Peut-être que c'est absurde, mais l'avez-vous déjà testé avec une valeur par défaut directement dans votre defaultConfig?

defaultConfig {
    buildConfigField "boolean", "ANALYTICS", "false"
}
1
Norbert

Enfin, on dirait que j'ai trouvé une raison. Le projet de bibliothèque a exactement le même ID de package que la variable principale app. Par conséquent, la variable intérieure BuildConfig du projet de bibliothèque ne contient pas de variable.

0
dilix