We are maintaining an Android Library. Lately we upgraded gradle, compileSdkVersion and support library versions. (only using com.android.support:design). Also we upgraded gcm-play-services
The library is published to Artifactory with its dependencies also in a pom file.
This upgrade works perfectly on projects with upto-date build tools and support libraries. However we are facing an issue with outdated projects that uses our library.
Here is the versions of library.
gradle android plugin -> 3.2.1
compileSdkVersion -> 28
targetSdkVersion -> 28
support library version -> 28.0.0
Here is the versions of project
compileSdkVersion -> 26
targetSdkVersion 26
support library version -> 26.0.1
and client support library dependencies
implementation 'com.android.support:cardview-v7:' + androidSupportV
implementation 'com.android.support:recyclerview-v7:' + androidSupportV
implementation 'com.android.support:appcompat-v7:' + androidSupportV
implementation 'com.android.support:design:' + androidSupportV
implementation 'com.android.support:support-v4:' + androidSupportV
implementation 'com.android.support:support-annotations:28.0.0'
after trying to build the project with new library, build fails with this log.
AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"/Users/umutyusuf/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/d4439e502685c256006fa4bec8edb713/res/values-v28/values-v28.xml","position":{"startLine":8,"startColumn":4,"startOffset":447,"endLine":11,"endColumn":12,"endOffset":684}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"/Users/umutyusuf/Documents/repo/core-bootstrap/core-android-client-app/PointrSample-Ozion-v5.0.8/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-v28/values-v28.xml","position":{"startLine":10}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/fontVariationSettings not found.","sources":[{"file":"/Users/umutyusuf/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/d4439e502685c256006fa4bec8edb713/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/ttcIndex not found.","sources":[{"file":"/Users/umutyusuf/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/d4439e502685c256006fa4bec8edb713/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
We avoid to do any manipulations in project code, so tried to solve it in library.
We downgrade the all versions to match the project versions. And published it with again with
compileSdkVersion -> 26
targetSdkVersion 26
support library version -> 26.0.1
But after that, we face a manifest merge error
Error:
Attribute meta-data#android.support.VERSION#value value=(26.0.1) from [com.android.support:cardview-v7:26.0.1] AndroidManifest.xml:25:13-35
is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:23:9-25:38 to override
This is originated from gcm-play-services which has support-v4:26.1.0 transitive dependency listed in dependency tree.
and to resolve it, added this to manifest
<meta-data
tools:node="replace"
tools:replace="android:value"
android:name="android.support.VERSION"
android:value="26.0.1" />
This made it all work. But now what would be the drawbacks of putting this meta tag to AndroidManifest file?
We tested this approach with all of compileSdkVersion 26, 27, 28
and all corresponding support library version. All seem to work.
We are search for better approaches to this.
Alternative solution we tried
We published the support library dependency in provided scope. But in this case projects using library should add their support design library to be able to use the with no problem. But even though they add the support library, would it be a problem if project had different support library version other then what library is compiled with?
This manifest meta-data may cause issues if your client uses a support library that forces another version of android.support the same way in its manifest. So avoid using this line in your SDK. Publishing with scope 'provided' will also not work and cause crashes if your client does not provide a support library as you said.
The solution I found was to use support:design:27.1.0 . This is the magical library that does not conflict with any other versions of the support libraries. After days of trying I was very happy to see that it resolves this issue, and does not cause crashes if the third-party uses another version of support design. Hope it solves your problem as well.
Related
dependencies {
implementation("com.android.support:appcompat-v7:28.0.0")
implementation("com.android.support.constraint:constraint-layout:2.0.4")
implementation("com.android.support:design:28.0.0")
testImplementation("junit:junit:4.+")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.2")
implementation("com.google.android.material:material:1.4.0-alpha02")
}
When I added the last line in the dependencies the first and third line says error and it says that
"
Dependencies using groupId com.android.support and androidx.* can not be combined but found com.android.support:design:28.0.0 and androidx.constraintlayout:constraintlayout:2.0.1 incompatible dependencies"
Please help me I am a beginner...
Android libraries used to be standalone, generally under the com.android.support name. The latest effort to organize those dependencies is called Jetpack. Jetpack introduced new code, package name and implementation, referred as Android X.
There are then, "support" (pre-X) and "AndroidX" dependencies. If your project is new, you should be starting with AndroidX out of the box. Otherwise you can migrate to it.
In your case your dependencies com.android.support:design and com.google.android.material are the same library, in its "support" and "AndroidX" form. Also com.android.support.test.espresso:.. became androidx.test.espresso:....
Check your project's gradle.properties for android.useAndroidX=true` to see if you're on an AndroidX project or not. Then use the proper dependencies.
Check https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
I've updated kotlin from 1.3.61 to 1.3.70 in my multiplatform project with android, jvm, ios and macosx64 targets not changing other code and whenever a gradle sync is attempted I get the following message (and the project build fails, of course):
CONFIGURE FAILED in 3s
Unable to find method 'org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.macosX64()Lorg/jetbrains/kotlin/gradle/plugin/mpp/KotlinNativeTargetWithHostTests;'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
I've tried the solutions described above, I also tried to clear .gradle/caches, but nothing changed. What might be the problem?
This happened because I had a buildSrc module where the dependencies' artifact names are declared like this:
object Deps {
object Android {
// artifacts
}
object Native {
// artifacts
}
// ...
}
and I had updated the kotlin dependency there, but I had forgotten to update the kotlin version in the build.gradle.kts of the buildSrc directory itself.
I am trying to build a kotlin library for discord bots, which can be found at https://github.com/TheDrone7/discord-kt , published to jcenter (bintray link - https://bintray.com/thedrone7/discordKt/discord-kt). The library has a few dependencies of it's own as well.
When I add my own library to my test app, the library's dependencies were not installed and I started getting some errors. Is there a way to specify the library's dependencies so that they get automatically installed when a user uses my library?
EDIT: -
So basically my test app's build.gradle.kts file's dependencies section is given below
dependencies {
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.theDrone:discordKt:0.0.1a")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
And my library is dependent on the following packages: -
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0
org.java-websocket:Java-WebSocket:1.4.0
com.beust:klaxon:5.0.5
org.slf4j:slf4j-jdk14:1.7.26
now when I run my test app, it shows gives error that there is no class named WebSocketClient which is a part of the org.java-websocket:Java-WebSocket:1.4.0 package and is also the base of my entire library.
When I add the listed packages to my test app's dependencies, it works perfectly fine. So is there a way that I could define in my library that the apps using it will also automatically depend on the packages my library depends on?
You declared the Java-WebSocket library as a dependency of your library using the implementation configuration.
This configuration means: I need that for my code to work, but it's an implementation detail and it's thus not part of my public API, so users of my library won't have access to it in their compile classpath.
So Gradle, when it generates the pom.xml file for your library, adds Java-WebSocket as a runtime dependency, and not as a compile dependency.
Read the java-library plugin documentation, which explains all of that in details. Once you have understood it, use api instead of implementation in your library's build.gradle.kts file for the dependencies that are part of your API, and should thus be compile dependencies and not runtime dependencies:
api("org.java-websocket:Java-WebSocket:1.4.0")
I have a Spring based web application which uses gRPC to communicate with my middle tier. I would like to be able to use the kotlin-script-util for the JSR-223 scripting engine. Being that kotlin-script-util relies on the kotlin-compiler dependency (which uses Guava), I am getting version conflicts with gRPC dependencies.
I see that there is a shaded kotlin-compiler-embeddable jar, but no kotlin-script-util that utilizes this dependency.
Is there something I can do to make these dependencies work together?
kotlin-script-util: 1.1.1
gRPC: 1.2.0
Unfortunately there is no ready-made solution for this problem. We'll try to address it in one of the next releases. (see KT-17556 for the relevant issue).
As a workaround, you can, for now, compile your own variant of the kotlin-script-utils. Just copy the project, change the appropriate dependency to the kotlin-compiler-embeddable, and then fix a few compilation errors by updating import statements (the com.intellij.openapi.* packages are relocated to org.jetbrains.kotlin.com.intellij.openapi.* in the kotlin-compiler-embeddable.)
I am looking at Play 2.0 for the first time. I installed it using homebrew
~/code $ brew info play
play: stable 2.1.0, HEAD
http://www.playframework.org/
/usr/local/Cellar/play/2.1.0 (3998 files, 254M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/play.rb
I create a new project and set it up for IntelliJ (12.0.4)
~/code $ play new playtime
...
play! 2.1.0 (using Java 1.7.0_15 and Scala 2.10.0), http://www.playframework.org
...
OK, application playtime is created.
...
~/code $ cd playtime/
~/code/playtime $ play idea
...
...
[info] Created /.../playtime/.idea_modules/playtime.iml
[info] Created /.../playtime/.idea_modules/playtime-build.iml
~/code/playtime $
I open IntelliJ and rebuild the project. I get
scala: Output path /.../playtime/project/target/scala_2.9.2 is shared between: Module 'playtime-build' production, Module 'playtime-build' tests
Currently external Scala compiler prohibits output path sharing.
Either disable the external build mode or configure separate output paths.
TIP: you can use Project Artifacts to combine compiled classes.
How to make a clean empty project that builds ?
Why does Play create a -build module ? What is it used for?
Why does this module reference a Scala 2.9.2 path ?
Libraries scala-2.9.2 and scala-2.10.0 also created, but not used. Why?
1) How to make a clean empty project that builds ?
Play 2.0 plugin for IDEA 12.1 (version 0.2.25 or 0.2.26) will be uploaded soon will be much better in this direction, I hope you will not have problems with compilation here.
2-3) Why does Play create a -build module ? What is it used for?
Build module is created for SBT build file. SBT depends on Scala 2.9.2 (that's why this module requires Scala 2.9.2), so to have better editor for such build file, SBT IDEA plugin creates this module (this is third-party plugin, our own SBT plugin will be implemented soon). However this is not right to create such confusing module, in Play 2.0 plugin 0.2.25 project creation will clean this module. So you will not have this confusing module.
4) scala-2.10.0 library is used in Scala facet for Scala compiler. However Scala compiler is not used in Play 2.0 project, we are using play compiler in our support (with bundled with play SBT compiler), so in general it's not used, but you still have this library, otherwise you will get some error messages from Scala compiler, what is Scala plugin usability problem, you can post new issue about it here: http://youtrack.jetbrains.com/issues/SCL