web-dev-qa-db-fra.com

Impossible de résoudre la variable '$ {project.groupId}'

J'ai migré mon projet vers AndroidX et j'ai eu ces erreurs lors de la construction du projet:

[TAG] Failed to resolve variable '${project.groupId}'   
[TAG] Failed to resolve variable '${project.version}'   
[TAG] Failed to resolve variable '${project.groupId}'   
[TAG] Failed to resolve variable '${project.version}'   
[TAG] Failed to resolve variable '${project.groupId}'   
[TAG] Failed to resolve variable '${project.version}'   

J'ai déjà essayé plusieurs solutions possibles:

  • Projet propre
  • Invalider le cache et redémarrer
  • Définissez enableJetifier sur false
  • Ajouter l'option --refresh-dependencies aux paramètres du compilateur 

Voici mon fichier de note de projet:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.Android.tools.build:gradle:3.2.1'
        classpath 'com.neenbedankt.gradle.plugins:Android-apt:1.8'
        classpath 'com.google.gms:google-services:4.0.0'
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Et voici mon fichier de classement de l'application:

apply plugin: 'com.Android.application'
apply plugin: 'io.fabric'

Android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    signingConfigs {
        //not showing this
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "my.app.package"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 59
        versionName "1.5.2"

        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true

    }
    dataBinding {
        enabled = true
    }
    // workaround for "duplicate files during packaging of APK" issue
    // see https://groups.google.com/d/msg/adt-dev/bl5Rc4Szpzg/wC8cylTWuIEJ
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'

        //Workaround to an issue due to google play-services 11.0.0 + rxJava
        exclude 'META-INF/rxjava.properties'
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-Android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release_config

        }
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix " - debug"
            debuggable true
        }
    }

    flavorDimensions "public"

    productFlavors {
        //not useful to show this
    }
}

ext {
    supportLibVersion = '28.0.0'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    implementation 'org.jetbrains:annotations-Java5:15.0'
    implementation project(path: ':security')

    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
    implementation 'com.google.Android.material:material:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.crashlytics.sdk.Android:crashlytics:2.9.3'
    implementation 'com.google.guava:guava:22.0-Android'
    implementation 'com.google.Android:flexbox:0.2.3'
    implementation 'com.google.code.gson:gson:2.8.0'

    implementation 'com.hannesdorfmann.fragmentargs:annotation:3.0.2'
    annotationProcessor 'com.hannesdorfmann.fragmentargs:processor:3.0.2'

    implementation 'com.f2prateek.Dart:dart:2.0.0'
    annotationProcessor 'com.f2prateek.Dart:dart-processor:2.0.0'

    implementation 'com.google.dagger:dagger:2.2'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.2'

    implementation 'com.couchbase.lite:couchbase-lite-Android:1.4.1'
    implementation 'com.couchbase.lite:couchbase-lite-Android-sqlcipher:1.4.1'

    implementation 'com.squareup.retrofit2:retrofit:2.2.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.2.0'

    implementation 'com.wang.avi:library:1.0.5'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.jaredrummler:twodscrollview:1.0.1'

    implementation 'com.arasthel:asyncjob-library:1.0.3'
    implementation('org.simpleframework:simple-xml:2.7.1') {
        exclude group: 'xpp3', module: 'xpp3'
        exclude group: 'stax', module: 'stax-api'
        exclude group: 'stax', module: 'stax'
    }

    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'io.reactivex:rxjava:1.1.6'

    debugImplementation 'com.squareup.leakcanary:leakcanary-Android:1.5.4'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-Android-no-op:1.5.4'
    testImplementation 'com.squareup.leakcanary:leakcanary-Android-no-op:1.5.4'

    implementation 'com.github.daniel-stoneuk:material-about-library:2.2.1'
    implementation 'org.Apache.commons:commons-lang3:3.4'

    implementation('com.github.hotchemi:permissionsdispatcher:3.0.1') {
        exclude module: "support-v13"
    }
    annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:3.0.1"

    implementation 'com.pascalwelsch.compositeandroid:activity:27.0.0'
    implementation 'com.pascalwelsch.compositeandroid:fragment:27.0.0'

    implementation 'commons-codec:commons-codec:1.10'

    implementation 'com.jakewharton.timber:timber:4.7.1'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'


}

apply plugin: 'com.google.gms.google-services'

// https://stackoverflow.com/a/49981467/3520621
configurations {
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains' , module:'annotations'
}

METTRE À JOUR

Je lance gradlew assembleDebug --stacktrace --debug --info et voici quelques informations supplémentaires:

...
Caused by: org.gradle.api.artifacts.transform.ArtifactTransformException: Failed to transform file 'dagger-compiler-2.2.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
...
Caused by: Java.lang.RuntimeException: Failed to transform 'C:\Users\me\.gradle\caches\modules-2\files-2.1\com.google.dagger\dagger-compiler\2.2\e411f732e5cd9697cdb291f6073b0d6ee2352023\dagger-compiler-2.2.jar' using Jetifier. Reason: The type does not support '.' as package separator! Received 'Java.lang.Object;Ljava.lang.Class'.. (Run with --stacktrace for more details.) To disable Jetifier, set Android.enableJetifier=false in your gradle.properties file.

Il semble donc que jetifier et dagger en soient la cause, mais jetifier est nécessaire pour la migration vers AndroidX et je ne souhaite pas supprimer dagger .

Si je définis Android.enableJetifier=false, j'ai plus de 50 problèmes concernant DataBinding.


UPDATE 2 Voici l'exception complète

org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:devDebugAnnotationProcessorClasspath'.
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.rethrowFailure(DefaultConfiguration.Java:944)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access$1600(DefaultConfiguration.Java:120)
        at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.Java:918)
        at org.gradle.api.internal.file.AbstractFileCollection.iterator(AbstractFileCollection.Java:68)
        at org.gradle.api.internal.changedetection.state.AbstractFileCollectionSnapshotter$FileCollectionVisitorImpl.visitCollection(AbstractFileCollectionSnapshotter.Java:72)
        at org.gradle.api.internal.file.AbstractFileCollection.visitRootElents(AbstractFileCollection.Java:234)
        at org.gradle.api.internal.file.CompositeFileCollection.visitRootElents(CompositeFileCollection.Java:185)
        at org.gradle.api.internal.changedetection.state.AbstractFileCollectionSnapshotter.snapshot(AbstractFileCollectionSnapshotter.Java:55)
        at org.gradle.api.internal.changedetection.state.DefaultClasspathSnapshotter.snapshot(DefaultClasspathSnapshotter.Java:42)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.snapshotTaskFiles(CacheBackedTaskHistoryRepository.Java:329)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.createExecution(CacheBackedTaskHistoryRepository.Java:151)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.access$100(CacheBackedTaskHistoryRepository.Java:61)
        at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository$1.getCurrentExecution(CacheBackedTaskHistoryRepository.Java:111)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.Java:208)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.Java:93)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.Java:50)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.Java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.Java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.Java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.Java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.Java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.Java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.Java:59)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.Java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.Java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.Java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.Java:256)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.Java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.Java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.Java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.Java:110)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.Java:249)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.Java:238)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.Java:123)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.Java:79)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.Java:104)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.Java:98)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.Java:663)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.Java:597)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.Java:98)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.Java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.Java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.Java:55)
Caused by: org.gradle.api.artifacts.transform.ArtifactTransforxception: Failed to transform file 'dagger-compiler-2.2.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
        at org.gradle.api.internal.artifacts.transform.UserCodeBackedTransforr.transform(UserCodeBackedTransforr.Java:89)
        at org.gradle.api.internal.artifacts.transform.TransformArtifactOperation.run(TransformArtifactOperation.Java:41)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.Java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.Java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.Java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.access$900(DefaultBuildOperationExecutor.Java:63)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$ParentPreservingQueueWorker.execute(DefaultBuildOperationExecutor.Java:378)
        at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.Java:230)
        at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.access$600(DefaultBuildOperationQueue.Java:172)
        at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.Java:209)
        at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.Java:203)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.Java:152)
        at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.Java:202)
        at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.Java:177)
        ... 3 more
Caused by: Java.lang.RuntiException: Failed to transform 'C:\Users\martin\.gradle\caches\modules-2\files-2.1\com.google.dagger\dagger-compiler\2.2\e411f732e5cd9697cdb291f6073b0d6ee2352023\dagger-compiler-2.2.jar' using Jetifier. Reason: The type does not supp
ort '.' as package separator! Received 'Java.lang.Object;Ljava.lang.Class'.. (Run with --stacktrace for more details.) To disable Jetifier, set Android.enableJetifier=false in your gradle.properties file.
        at com.Android.build.gradle.internal.dependency.JetifyTransform.transform(JetifyTransform.kt:204)
        at org.gradle.api.internal.artifacts.transform.TransformArtifactsAction.apply(TransformArtifactsAction.Java:44)
        at org.gradle.api.internal.artifacts.transform.TransformArtifactsAction.apply(TransformArtifactsAction.Java:29)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache$TransformAction.execute(DefaultTransfordFileCache.Java:224)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache$TransformAction.execute(DefaultTransfordFileCache.Java:211)
        at org.gradle.internal.resource.local.DefaultPathKeyFileStore$1.execute(DefaultPathKeyFileStore.Java:111)
        at org.gradle.internal.resource.local.DefaultPathKeyFileStore$1.execute(DefaultPathKeyFileStore.Java:107)
        at org.gradle.internal.resource.local.DefaultPathKeyFileStore.doAdd(DefaultPathKeyFileStore.Java:160)
        at org.gradle.internal.resource.local.DefaultPathKeyFileStore.add(DefaultPathKeyFileStore.Java:107)
        at org.gradle.internal.resource.local.DefaultPathKeyFileStore.add(DefaultPathKeyFileStore.Java:50)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache$1$1.create(DefaultTransfordFileCache.Java:143)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache$1$1.create(DefaultTransfordFileCache.Java:122)
        at org.gradle.cache.internal.LockOnDemandCrossProcessCacheAccess.withFileLock(LockOnDemandCrossProcessCacheAccess.Java:89)
        at org.gradle.cache.internal.DefaultCacheAccess.withFileLock(DefaultCacheAccess.Java:193)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.withFileLock(DefaultPersistentDirectoryStore.Java:158)
        at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.withFileLock(DefaultCacheFactory.Java:187)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache$1.create(DefaultTransfordFileCache.Java:122)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache$1.create(DefaultTransfordFileCache.Java:115)
        at org.gradle.cache.internal.ProducerGuard$AdaptiveProducerGuard.guardByKey(ProducerGuard.Java:97)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache.loadIntoCache(DefaultTransfordFileCache.Java:115)
        at org.gradle.api.internal.artifacts.transform.DefaultTransfordFileCache.getResult(DefaultTransfordFileCache.Java:107)
        at org.gradle.api.internal.artifacts.transform.UserCodeBackedTransforr.transform(UserCodeBackedTransforr.Java:87)
        ... 16 more
Caused by: Java.lang.IllegalArguntException: The type does not support '.' as package separator! Received 'Java.lang.Object;Ljava.lang.Class'.
        at com.Android.tools.build.jetifier.core.type.JavaType.<init>(JavaType.kt:28)
        at com.Android.tools.build.jetifier.processor.transform.bytecode.asm.CustomRemapper.mapValue(CustomRemapper.kt:49)
        at org.objectweb.asm.commons.thodRemapper.visitLdcInsn(thodRemapper.Java:179)
        at org.objectweb.asm.ClassReader.readCode(ClassReader.Java:1582)
        at org.objectweb.asm.ClassReader.readthod(ClassReader.Java:1126)
        at org.objectweb.asm.ClassReader.accept(ClassReader.Java:698)
        at org.objectweb.asm.ClassReader.accept(ClassReader.Java:500)
        at com.Android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransforr.runTransform(ByteCodeTransforr.kt:39)
        at com.Android.tools.build.jetifier.processor.Processor.visit(Processor.kt:328)
        at com.Android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:41)
        at com.Android.tools.build.jetifier.processor.Processor.visit(Processor.kt:316)
        at com.Android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:66)
        at com.Android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:312)
        at com.Android.tools.build.jetifier.processor.Processor.transform(Processor.kt:175)
        at com.Android.build.gradle.internal.dependency.JetifyTransform.transform(JetifyTransform.kt:199)
        ... 37 more
14
MHogge

Après avoir migré vers Android, Android Studio ne peut pas résoudre les classes dagger-Android et dagger-Android-support, comme DaggerAppCompatActivity. Lien d'émission

5
Kourosh

J'ai résolu cette erreur en changeant les variables dans build.gradle (Module), par exemple, j'ai changé 

implementation "androidx.room:room-rxjava2:$version"

À

implementation "androidx.room:room-rxjava2:2.1.0-alpha03"

et résolu :)

  • problème est survenu après la mise à jour vers AndroidStudio à 3.3 Stable! version

J'utilise Androidx, ... mais tout fonctionnait bien avant de mettre à niveau Android Studio.

3
Hamed Jaliliani

La raison supplémentaire est que Jetifier essaie de créer des bibliothèques qu'il n'est pas censé. À partir du plugin Android Gradle 3.3.0-rc01 et 3.4.0-alpha04, il existe une solution de contournement permettant de désactiver la définition de la bibliothèque de bibliothèques spécifiées en les ajoutant à la liste séparée par des virgules à gradle.properties:

Android.jetifier.blacklist=byte-buddy,guava

La solution est trouvée ici

1
Aleksandr