Не удалось разрешить переменную '$ {project.groupId}'

Я переношу свой проект на AndroidX, и я получил эти ошибки при создании проекта:

[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}'   

Я уже пробовал несколько возможных решений:

  • Чистый проект
  • Недействительный кэш и перезагрузка
  • Установите enableJetifier в false
  • Добавить параметр --refresh-dependencies к настройкам компилятора

Вот мой файл проекта gradle:

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
}

И вот мой файл приложения gradle:

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'
}

ОБНОВИТЬ

Я запускаю gradlew assembleDebug --stacktrace --debug --info и вот еще информация:

...
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.

Так что, похоже jetifier и кинжал является причиной, но jetifier необходимо для перехода к AndroidX, и я не хочу, чтобы удалить кинжал.

Если я установлю android.enableJetifier=false меня есть более 50 проблем с DataBinding.


ОБНОВЛЕНИЕ 2 Вот полное исключение

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

Ответ 1

После перехода на androidx Android Studio не может разрешить классы dagger-android и dagger-android-support, такие как DaggerAppCompatActivity. Ссылка на проблему

Ответ 2

У меня все время одна и та же проблема, просто добавьте что-то в Gradle a Sync снова, и проблема была решена, я думаю, это ошибка от Android Studio

Ответ 3

Что я сделал, чтобы решить эту проблему, так это File - Invalidate Caches/Restart.

Ответ 4

Я решил эту ошибку, изменив переменные в build.gradle(Module) на их версии, например, я изменил

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

К

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

и решил :)

  • проблема произошла после обновления до AndroidStudio до 3.3 стабильной! версия

Я использую Androidx, но до обновления Android Studio все работало отлично.

Ответ 5

Еще одна причина заключается в том, что Jetifier пытается создать библиотеки, которые не должны этого делать. Начиная с плагина Android gradle 3.3.0-rc01 и 3.4.0-alpha04, существует обходной путь, позволяющий отключить создание дубликатов указанных библиотек путем добавления их в список, разделенный запятыми, в gradle.properties:

android.jetifier.blacklist=byte-buddy,guava

Решение найдено здесь

Ответ 6

Когда я столкнулся с этой проблемой, я решил, удалив все файлы в .gradle/. А потом я открыл андроид студию и снова строю. Это было сработано и решено.

Ответ 7

   <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="@string/authorities"
        android:exported="false"
        android:grantUriPermissions="true"
        >
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/filepaths" />
    </provider>

Ответ 8

Я решил эту ошибку обновлением:

  • Android Studio до версии 3.5.1
  • Gradle до 5.1.1 (от gradle-4.10.1)

    In gradle.wrapper.properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip