With a build.gradle like this (simplified):
buildscript {
...
dependencies {
classpath "com.android.tools.build:gradle:7.3.1"
classpath "com.huawei.agconnect:agcp:1.7.3.302"
}
}
Module build.gradle (merely alike the Enabling APM tutorial):
plugins {
id "com.android.application"
id "com.huawei.agconnect"
}
agcp {
enableAPMS true
}
dependencies {
implementation "com.huawei.hms:base:6.7.0.300"
implementation "com.huawei.agconnect:agconnect-core:1.7.3.302"
implementation "com.huawei.agconnect:agconnect-apms:1.6.1.303"
}
I get this warning:
--W- [APMSClassVisitor] agconnect-apms version [1.6.1.303] is not same with agconnect-apms-plugin version [1.5.2.310], please update one of them, or invalidate AndroidStudio cache if these versions have been same.
Followed by further problems:
[Instrument] an error occurred while instrumenting an unknown class, skipping it: Module requires ASM6
[Instrument] an error occurred while instrumenting an unknown class, skipping it: NestHost requires ASM7
[Instrument] an error occurred while instrumenting an unknown class, skipping it: NestMember requires ASM7
How to upgrade the (bundled) agconnect-apms-plugin version to 1.6.1.303?
To make the versions match, one has to add agconnect-apms-plugin version 1.6.1.300:
buildscript {
...
ext {
agp_version = '7.3.1'
hms_version = '6.7.0.300'
agc_version = '1.7.3.302'
apms_version = '1.6.1.300'
}
dependencies {
classpath "com.android.tools.build:gradle:$agp_version"
classpath "com.huawei.agconnect:agcp:$agc_version"
classpath "com.huawei.agconnect:agconnect-apms-plugin:$apms_version"
}
}
And disable the integrated agconnect-apms-plugin 1.5.2.310, which is otherwise being preferred:
plugins {
id "com.android.application"
id "com.huawei.agconnect"
}
dependencies {
implementation "com.huawei.hms:base:$hms_version"
implementation "com.huawei.agconnect:agconnect-core:$agc_version"
implementation "com.huawei.agconnect:agconnect-apms:$apms_version"
}
Note: enableAPMS false is the default value; true is what caused the version conflict.
Related
Getting error below while using dagger-hilt
Unsupported metadata version. Check that your Kotlin version is >=
1.0: java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
Please note that I already followed some topics from stackoverflow and other documentation
Hilt Unsupported metadata version in Kotlin
Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException
https://github.com/google/dagger/issues/2379
Using below app gradle configuration
compileSdk 32
defaultConfig {
applicationId "com.test.plantdemo"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
}
Android plugin
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
App level dependency
dependencies {
implementation "androidx.work:work-runtime-ktx:2.5.0"
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
kapt "com.google.dagger:hilt-compiler:2.35.1"
implementation "com.google.dagger:hilt-android:2.35.1"
}
Top level dependency I used
dependencies {
// other plugins...
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40'
}
Top level gradle Plugin
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
id 'com.google.dagger.hilt.android' version '2.41' apply false
}
Error window shows below error
[Hilt] Processing did not complete.
See error above for details.
Execution failed for task ':app:kaptDebugKotlin'.
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
java.lang.reflect.InvocationTargetException (no error message)
step I followed after adding library
Step1: Android application class
#HiltAndroidApp
class PlantApplication: Application() {
}
Step2: Module calss
#Module
#InstallIn(SingletonComponent::class)
object MainModule {
}
Step3: View Model
#HiltViewModel
class PlantListBaseViewModel #Inject constructor(): ViewModel() {
}
Step4: fragment
#AndroidEntryPoint
class PlantListBaseFragment : Fragment() {
}
I recommend using the latest stable version of Dagger. Mine is working with these versions:
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
implementation "com.google.dagger:dagger-android-support:2.42"
implementation "com.google.dagger:hilt-android:2.42"
I hope it'll work
Update:
If you are curious about the reason, here:
Looks like Dagger needs to update the kotlin-metadata-jvm library to 0.4.0 which supports reading metadata from Kotlin 1.7, current version is 0.3.0, you might be able to work around the issue by forcing an update on the transitive dep, likely depending on it directly, something like this:
dependencies {
//Not a processor, but forces Dagger to use newer metadata lib
kapt "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2"
}
you can follow that here: https://github.com/google/dagger/issues/3383
So I'm trying to add AppGallery connect gradle plugin to my android project using new Kotlin DSL syntax. But I'm getting error like this:
org.gradle.internal.exceptions.LocationAwareException: Build file 'D:\#KERJAAN\devbase\sample\build.gradle.kts' line: 3
Plugin [id: 'com.huawei.agconnect', version: '1.6.3.300'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.huawei.agconnect:com.huawei.agconnect.gradle.plugin:1.6.3.300')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo
maven(https://developer.huawei.com/repo/)
What i did was adding repository for plugin like this in settings.gradle.kts:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven { setUrl("https://developer.huawei.com/repo/") }
}
}
And adding the plugin like this in app's build.gradle.kts:
plugins {
id("com.huawei.agconnect") version "1.6.3.300"
}
Interestingly, It works if using classpath from the root build.gradle.kts. Does anyone know why?
Any Gradle plugin (this is not AGC specific at all) can only be loaded at the root project level, and then usually be applied on the module level. I've just tried to remove the buildscript block (alike in the question), which indeed leads to:
Plugin [id: 'com.huawei.agconnect', version: '1.7.3.302', apply: false] was not found in any of the following sources:
maven(https://developer.huawei.com/repo/)
Plugin Repositories (could not resolve plugin artifact 'com.huawei.agconnect:com.huawei.agconnect.gradle.plugin:1.7.3.302')
The plugin dependency won't resolve, while the pluginManagement keeps adding .gradle.plugin. If the repository would know about the full and not only the shorthanded name agcp, this should work out of the box (that's actually the default expected package name, unless changing it):
com.huawei.agconnect:com.huawei.agconnect.gradle.plugin:1.7.3.302
And this doesn't match:
com.huawei.agconnect:agcp:1.7.3.302
One can use pluginManagement.resolutionStrategy as a temporary workaround ...
The settings.gradle is being used to rewrite the wrongfully assumed package name:
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
google()
maven { url 'https://developer.huawei.com/repo/' }
}
plugins {}
resolutionStrategy {
eachPlugin {
if (it.requested.id.getNamespace() == 'com.huawei.agconnect') {
println ">> ${it.requested.id.id}"
if (it.requested.id.id == 'com.huawei.agconnect.agcp') {
it.useModule('com.huawei.agconnect:agcp:1.7.3.302')
}
if (it.requested.id.id == 'com.huawei.agconnect.apms') {
it.useModule('com.huawei.agconnect:agconnect-apms-plugin:1.6.1.300')
}
println ">> ${it.target}"
} else {
println "> ${it.target}"
}
}
}
}
plugins have to be defined in build.gradle:
plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
id "com.huawei.agconnect.agcp" version "1.7.3.302" apply false
id "com.huawei.agconnect.apms" version "1.6.1.300" apply false
}
println will output the updated (fake) id to artifact mapping it.target:
[
id: 'com.huawei.agconnect.agcp',
version: '1.7.3.302',
artifact: 'com.huawei.agconnect:agcp:1.7.3.302',
apply: false
]
When applying it, one still needs to use the real id:
apply plugin: 'com.huawei.agconnect'
It is just that (as of version 1.7.3.302) APMSTransform has some check in place, which requires to explicitly put AGP on classpath. The buildscript block is "almost" obsolete, if not APMSTransform would wrongfully assume, that it is the only place where the Android Gradle plugin can be loaded.
/** Still required due to AGCP plugin. */
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
}
}
It would also need to check for either of these plugins:
plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
}
For example:
project.getPluginManager().hasPlugin('com.android.application') || project.getPluginManager().hasPlugin('com.android.library')
In order to make this work flawlessly (without resolutionStrategy), this would require an updated check, in order not to get com.android.tools.build:gradle is no set in the build.gradle file and
also an URL rewrite, which would handle the package name's .gradle.plugin suffix properly, so that com.huawei.agconnect.gradle.plugin and agcp would result in the same package download. resolutionStrategy indeed is the workaround and not the answer.
Don't use
plugins {
id("com.huawei.agconnect") version "1.6.3.300"
}
PLS old way like use
dependencies {
// 增加agcp插件配置,推荐您使用最新版本的agcp插件。
classpath 'com.huawei.agconnect:agcp:1.6.3.300'
// important add next line , huawei dependencies agp.
classpath 'com.android.tools.build:gradle:7.1.2'
}
I have and Android module which contains a Gradle JavaExec task. When running the JavaExec task, I would like it to use the classpath of the module.
The JavaExec task executes a Kotlin main function which uses some 3rd party library (kotlinpoet). But when running the Gradle task, I'm getting a java.lang.ClassNotFoundException due to kotlinpoet library not being included in the classpath.
I've found similar issues in StackOverflow, and tried many variants for the classpath parameter in the myTask, but nothing that worked.
Here's is the build.gradle file:
plugins {
id 'com.android.library'
id 'kotlin-android'
}
apply plugin: 'kotlinx-serialization'
android {
compileSdkVersion 30
defaultConfig {
...
}
buildTypes {
...
}
compileOptions {
...
}
kotlinOptions {
jvmTarget = '1.8'
}
}
task myTask(type: JavaExec) {
classpath += (files('build/tmp/kotlin-classes/debug', "${android.sdkDirectory}/tools/lib/kotlin-stdlib-1.1.3-2.jar", getBuildDir().toString() + "/intermediates/classes/debug"))
main = 'com.foo.app.home.parser.MainKt'
}
tasks.named('build') { dependsOn('configGeneratorTask') }
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:$androidx_core_ktx"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinx_serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinx_serialization_version"
implementation 'com.squareup:kotlinpoet:1.10.2'
}
You can get the classpath from each variant. This should do the trick:
afterEvaluate { // needed to make sure all android setup is available
task myTask(type: JavaExec) {
// you probably don't even need to set all these paths manually anymore
classpath += files(
'build/tmp/kotlin-classes/debug',
"${android.sdkDirectory}/tools/lib/kotlin-stdlib-1.1.3-2.jar",
getBuildDir().toString() + "/intermediates/classes/debug"
)
android.applicationVariants.each { variant -> // or libraryVariants
// add each variant's compiler classpath onto this classpath
classpath += variant.javaCompileProvider.get().classpath
}
// uncomment the line below if you need the android.jar etc
// classpath += files(android.bootClasspath)
// setting main directly is now deprecated. Set it like this:
mainClass.set('com.foo.app.home.parser.MainKt')
}
}
Also see this answer here: https://stackoverflow.com/a/37268008/3968618
How to this i am new on Android Studio.
The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.0,15.0.0], [15.0.2,15.0.2]], but resolves to 15.0.2. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
As reported here:
You will need to update the version of the latter dependency to 15.0.2. This addresses the issue where version 3.3.0 of the Google Services Gradle plugin reports: The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.0,15.0.0], [15.0.2,15.0.2]], but resolves to 15.0.2...
Then update your google play services plugin to 3.3.0
classpath 'com.google.gms:google-services:3.3.0'
and update the dependencies to 15.0.2.
Resolve this issue with me - If You are choosing Firestore Database then do this:
first We will add updated these things in Gradle :
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
}
}
allprojects {
// ...
repositories {
// ...
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
after this update :
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
implementation 'com.google.firebase:firebase-core:16.0.0'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Then Rebuild or Sunc Now , issue will be resolve.
if You are working on RealTime Database then do this thing :-
Set Dependency :
implementation 'com.google.firebase:firebase-database:15.0.0'
and remove above FireStore Dependency.
This will sure resolve your issue ... If you like then vote for me
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
}
}
This works for me. By adding the latest version, i.e 4.0.1
For databinding
1) I have added
android {
dataBinding {
enabled = true
}
to my project build.gradle, but this error occurs:
Error:(5, 0) Gradle DSL method not found: 'dataBinding()'
Possible causes:
.The project 'exampleDatabinding' may be using a version of Gradle that does
not contain the method.
Gradle settings
.The build file may be missing a Gradle plugin.
Apply Gradle plugin
2) Then I added:
apply plugin: "com.android.databinding" (to project build.gradle)
and classpath "com.android.databinding:dataBinder:1.0-rc1" (to project build.gradle)
But the same error occured.
In the file build.gradle of the project add the dependency
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
And in the file build.gradle of the module include the dataBinding section:
android{
...
dataBinding {
enabled = true
}
...
}
The versions of build.gradle can be found here: Versions
The project 'exampleDatabinding' may be using a version of Gradle that does
not contain the method.
You need to update your gradle to latest version 2.10
To update gradle do as follows
YourProject->gradle->wrapper->gradle-wrapper.properties
update the distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.
Also add dataBinding:
android{
...
dataBinding {
enabled = true
}
...
}
Also update your classpath:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}