I was writing my own navigation for compose, by that ive created a seperate project that contains the library. after some time i could reuse the project in an compose desktop application. after some time i recieved emails about my project not running on andoid anymore. ive got this stacktrace: (other versions results in othewr method names but everytime method not found)
No virtual method setUi(Lkotlin/jvm/functions/Function5;)V in class Lcom/nom/rougthnav/ScreenConfiguration; or its super classes (declaration of 'com.nom.rougthnav.ScreenConfiguration' appears in /data/data/com.nom.myapplication/code_cache/.overlay/base.apk/classes.dex)
at com.nom.myapplication.MainActivity$onCreate$1$1$1$router$2$1.invoke(MainActivity.kt:33)
at com.nom.myapplication.MainActivity$onCreate$1$1$1$router$2$1.invoke(MainActivity.kt:31)
at com.nom.rougthnav.Router.screen(Router.kt:75)
at com.nom.rougthnav.Router.screen(Router.kt:47)
this keeps appearing only if i use this as an aar library, so ive researched about this.
ive analyzed my aar files and the final apk that got installed everywhere is the method present and i have no dependency version conflict. if i use the files directly in those projects its working like a charm.
ive thought that this might be resolved if i use another set of dependencies, so ive created a new sample project barely used anything, but got this error again in any version of my aar file.
an example:
ive got this interface for the configuration:
interface RouterScope<K> {
fun <T> screen(
tag: K,
modelFactory: () -> T,
block: #Composable (model: T, back: Back, nav: Nav<K>) -> Unit
)
var initialTag: K
var link: String
fun route(tag: K, initial: K, block: RouterScope<K>.() -> Unit)
var tagConverter: ((String) -> K)?
}
but the screen method keeps disappearing. im wondering if this is linked with the composeable annotation. But the composeable annotation is used the same way in other android libs.
Any hint appreciated, im finally stuck. here is my build.gradle.kts:
plugins {
id("org.jetbrains.kotlin.android")
id("com.android.library")
`maven-publish`
}
android {
compileSdk = 30
defaultConfig {
// applicationId = "com.nom.rougthnav"
minSdk = 27
targetSdk = 30
// versionCode = 1
// versionName = "1.0"
version = "1.6"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("com.google.android.material:material:1.4.0")
val compose = "1.0.3"
implementation("androidx.compose.ui:ui:$compose")
implementation("androidx.compose.ui:ui-tooling-preview:$compose")
implementation("androidx.compose.ui:ui-tooling:$compose")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
}
afterEvaluate {
publishing {
publications {
register("release",MavenPublication::class){
from(components["release"])
groupId = "com.nom.roughtnav"
artifactId = "core"
version = "${project.version}"
}
//
}
}
}
Related
I have separate groovy script that adds flavors to my android project. And i can apply it no problem in build.gradle files. But calling it from kotlin build.gradle.kts file im getting error.
I have flavors.gradle file
ext.configFlavors = {
flavorDimensions "brand"
productFlavors {
myBrand {
dimension "brand"
}
}
And i can easilly call this from build.gradle files
android{
...
with configFlavors
}
But in build.gradle.kts files i get:
Could not find method flavorDimensions() for arguments [brand] on project ': myModule' of type org.gradle.api.Project.
My build.gradle.kts looks like this:
import com.android.build.gradle.LibraryExtension
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
apply(from ="${rootProject.projectDir}/buildSrc/flavors.gradle" )
val configFlavors: groovy.lang.Closure<LibraryExtension> by extra
android {
compileSdk = Versions.compile_sdk_version
defaultConfig {
minSdk = Versions.min_sdk_version
targetSdk = Versions.target_sdk_version
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
//Dev
create("dev") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
//Staging
create("staging") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
//Production
create("production") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
// I am able to call the closure but i got the error
configFlavors()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
}
}
dependencies {
implementation(fileTree("include" to listOf("*.jar"), "dir" to "libs"))
implementation(project(":domain"))
// list of dependencies
}
Extra properties can be accessed with the following syntax:
// get an extra property from the current project
val myProperty: String by extra
// or from the root project
val myNewProperty: String by rootProject.extra
However, configFlavours is not a simple primitive value, it's a Closure.
It's possible to access Closures in Kotlin, but without knowing what type the Closure should apply to, it's not possible to use it.
// Replace `Any` with the actual type, if known
val configFlavours: groovy.lang.Closure<Any> by extra
println(configFlavours)
// > Configure project :
// flavours_atn69ibjqzvnwf0cp7hb75l45$_run_closure1#398b577e
There are more through examples in the Gradle docs
P.S. your code has both flavour and flavor - pick a spelling please :)
I ended up adding another closure that takes libraryExtension as parameter. And using it from gradle.build.kts files. It is not optimal but it seems to work.
ext.configFlavorsWithParam = { libraryExtension ->
libraryExtension.flavorDimensions "brand"
libraryExtension.productFlavors {
brand1 {
dimension "brand"
}
}
And im calling it like this
android{
...
configFlavorsWithParam(this)
}
Previously with Groovy, you could easily move parts of your build.gradle to separate files. But now using the Kotlin DSL I get unresolved references and I can't seem to figure out why.
If I have this in my app/build.gradle.kts file, everything compiles nicely.
/**
* Apply shared configurations to the android modules.
*/
fun com.android.build.gradle.BaseExtension.baseConfig() {
plugins.withType<com.android.build.gradle.api.AndroidBasePlugin> {
configure<com.android.build.gradle.BaseExtension> {
defaultConfig {
compileOptions {
compileSdkVersion(33)
defaultConfig {
minSdk = 23
targetSdk = 33
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile> {
kotlinOptions.jvmTarget = "11"
}
}
/**
* Apply configuration settings that are shared across all modules.
*/
fun PluginContainer.applyBaseConfig(project: Project) {
whenPluginAdded {
when (this) {
is com.android.build.gradle.internal.plugins.AppPlugin -> {
project.extensions
.getByType<com.android.build.gradle.AppExtension>()
.apply {
baseConfig()
}
}
is com.android.build.gradle.internal.plugins.LibraryPlugin -> {
project.extensions
.getByType<com.android.build.gradle.LibraryExtension>()
.apply {
baseConfig()
}
}
}
}
}
But as soon as I move these into gradle/gradle-base-config.gradle.kts, it will no longer compile. I'm assuming because it has no reference to what it is etc, but I can't find anything anywhere on how to expose this. This also happens for configurations should as jacoco configurations when using apply(from = "${projectDir}/gradle/jacoco.gradle.kts there's unresolved references in the kts file, but moving it directly into my app build.gradle everything compiles.
This is unfortunately not supported by kotlin dsl as described here: type safe accessors.
However you can use precompiled script plugins to achieve similar behavior
I'm getting a java.lang.NoSuchMethodError exception when trying to run setContent{ Composable() }.
Full code:
class ComposeFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
ComposeView(requireContext()).apply { setContent { Text("hello") } }
}
Full exception:
java.lang.NoSuchMethodError: No virtual method setContent(Lkotlin/jvm/functions/Function0;)V in class Landroidx/compose/ui/platform/ComposeView; or its super classes (declaration of 'androidx.compose.ui.platform.ComposeView' appears in /data/app/~~3OmVKUoYitZ_S4H81xmyuw==/my.app.package-PAQxAKmtRuhnzp4M2DME8w==/base.apk)
Solutions/answers to similar questions suggest adding buildFeatures { compose = true } or kotlinCompilerExtensionVersion, I have already done this but the issue persists.
My full compose Gradle config is as follows:
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
useIR = true
}
buildFeatures {
compose = true
}
composeOptions{
kotlinCompilerExtensionVersion = "1.0.5"
}
implementation( "androidx.activity:activity-compose:1.3.1" )
implementation( "androidx.activity:activity-compose:1.3.1" )
implementation( "androidx.compose.material:material:1.0.5" )
implementation( "androidx.compose.animation:animation:1.0.5" )
implementation( "androidx.compose.ui:ui-tooling:1.0.5" )
implementation( "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07" )
androidTestImplementation( "androidx.compose.ui:ui-test-junit4:1.0.5" )
Ran into the same exception today, so I put my solution here in case someone else needs it.
In my case, it was because the setup below was missing from the build.gradle file, of the android section
buildFeatures.compose = true
composeOptions {
kotlinCompilerExtensionVersion = Versions.COMPOSE
}
Version.COMPOSE is the compose version, in my case it was 1.1.0-alpha05
I had the same issue and it was solved by adding the following lines to my app's build.gradle file:
android {
buildFeatures {
compose true
}
}
Your Compose version is very old and is almost certainly the reason for your problems. Update your project gradle with the following. Make sure to upgrade the plugin versions as well:
buildscript {
ext {
compose_version = '1.1.0-rc01'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0'
}
}
Make sure all your dependencies are using the most recent stable version.
You should also update your Kotlin plugin version:
211-1.6.10-release-923-AS7442.40
If you don't know where to set this, click on:
Android Studio > Preferences > Languages & Frameworks > Kotlin
Finally, I strongly recommend that you use Java 11 instead of 8 and set your app's build.gradle to this:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
apply from: 'codeinc.gradle'
android {
compileSdkVersion 31
buildToolsVersion "31.0.0"
defaultConfig {
applicationId "mydomain.myapp.blablahblah"
minSdkVersion 21
targetSdkVersion 31
versionName "1.0.0"
versionCode 1
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.6.0'
}
}
Add this lines to your module's gradle file :
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = rootProject.extra["compose_version"] as String
}
If you work on muli-module project, you have to add this for each compose included modules.
Add to build.gradle.kts
android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerVersion = Depends.kotlin
kotlinCompilerExtensionVersion = Depends.compose
}
}
#Composable
private fun Greeting() {
Text(
text = stringResource(R.string.channel_id),
style = MaterialTheme.typography.h5,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 10.dp)
.wrapContentWidth(Alignment.CenterHorizontally)
)
}
class ShowAvatarImageActivity : AppCompatActivity() {
......
val greeting = findViewById<ComposeView>(R.id.greeting)
greeting.setContent {
Greeting()
}
......
}
Gradle Config such as you
My xml file like this
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#000">
......
<androidx.compose.ui.platform.ComposeView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="#+id/greeting"
android:layout_width="match_parent"
android:layout_height="200dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I use pure Kotlin code for a comparison of separate functions to test
For integration of composeView you must have to add below dependency;
implementation 'androidx.activity:activity-compose:1.4.0'
Also, don't forget supporting version of kotlin with compose version.
If you are using compose version as 1.1.1 you have to use kotlin version
I had the same issue. buildFeatures { compose = true } and kotlinCompilerExtensionVersion were also set. Since I had an old configuration of the project the solution was in adding the following code to the root/build.gradle
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}
However, I was also using buildSrc and it became a nightmare to migrate from this approach to the plugins. Keep calm and several days.
After everything was migrated I was able to launch the code without crashing.
I have a KMM application in which the android target uses Jetpack Compose. I am getting the following error when I try to use a drawable resource:
e: [...]/OnboardingScreen.kt: (33, 46): Unresolved reference: drawable
This is the result of trying to access a drawable via painterResource(id = R.drawable.ic_icon).
I have tried the following things to fix the issue:
Clean and build the project
Invalidate cache and restart
Fix all warnings when executing ./gradlew assembleDebug
The static R class is correctly imported
Nothing of the above solves the problem.
This is my build.gradle.kts of the android module:
plugins {
id("com.android.application")
kotlin("android")
}
val composeVersion = findProperty("version.compose") as String
val composeNavigationVersion = findProperty("version.composeNavigation") as String
val koinVersion = findProperty("version.koin") as String
android {
compileSdk = (findProperty("android.compileSdk") as String).toInt()
defaultConfig {
applicationId = "com.app.app.android"
minSdk = (findProperty("android.minSdk") as String).toInt()
targetSdk = (findProperty("android.targetSdk") as String).toInt()
versionCode = 1
versionName = "1.0"
}
buildFeatures {
compose = true
}
// Set both the Java and Kotlin compilers to target Java 8.
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
composeOptions {
kotlinCompilerExtensionVersion = composeVersion
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
dependencies {
implementation(project(":shared"))
// Android
implementation("com.google.android.material:material:1.4.0")
// Jetpack Compose
implementation("androidx.compose.ui:ui:$composeVersion")
implementation("androidx.compose.ui:ui-tooling:$composeVersion")
implementation("androidx.compose.foundation:foundation:$composeVersion")
implementation("androidx.compose.material:material:$composeVersion")
implementation("androidx.compose.material:material-icons-core:$composeVersion")
implementation("androidx.compose.material:material-icons-extended:$composeVersion")
implementation("androidx.activity:activity-compose:$composeVersion")
implementation("androidx.navigation:navigation-compose:$composeNavigationVersion")
// Koin
implementation("io.insert-koin:koin-android:$koinVersion")
}
configurations.all {
resolutionStrategy {
force("org.jetbrains.kotlin:kotlin-stdlib:1.5.31")
}
}
My build.gradle.kts of the shared module:
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
}
version = "1.0"
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64() // sure all ios dependencies support this target
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.1"
podfile = project.file("../ios/Podfile")
framework {
baseName = "shared"
}
}
val multiplatformVersion = findProperty("version.multiplatformSettings") as String
val koinVersion = findProperty("version.koin") as String
val coroutinesVersion = findProperty("version.coroutines") as String
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.russhwolf:multiplatform-settings-no-arg:$multiplatformVersion")
implementation("io.insert-koin:koin-core:$koinVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
}
android {
compileSdk = 31
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 22
targetSdk = 31
}
}
And finally, my gradle.properties:
# Gradle
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
# Kotlin
kotlin.code.style=official
# Android
android.useAndroidX=true
android.compileSdk=31
android.targetSdk=31
android.minSdk=22
# MPP
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.enableDependencyPropagation=false
kotlin.native.ignoreDisabledTargets=true
# Common versions
version.multiplatformSettings=0.8.1
version.koin=3.1.4
version.coroutines=1.5.2-native-mt
# Android versions
version.compose=1.0.5
version.composeNavigation=2.4.0-rc01
Thanks in advance.
That's how you reference image resources:
import com.your.package.R
val img = R.drawable.img_name
or
val img = com.your.package.R.drawable.img_name
Denny Kurniawan's comment above pointed me in the right direction. I had a similar problem after changing the name of my project. At the top of your 'OnboardingScreen.kt' file, check to see if the full 'package' name matches your actual project's name, e.g. "package com.android.application".
If the package name listed in 'OnboardingScreen.kt' is not the same as your actual project's name, then the static R class is probably not being imported correctly and, hence, this error.
In other words, the full package name in 'OnboardingScreen.kt' should match the name of the folder shown under 'app->src->main->java'. Hope this helps someone as it did me.
for me, this error happen because I drag my image to the resource manager, I solve it by importing the images manually with the "Import Drawables" button
I have a project with the standard java library and this creates several .jar files, one being a docset and another the source set. Now I have successfully created an android-library using the maven-publish plugin, but when I add the .aar files to another project, they don't contain neither source nor comments as the .jar version did, so I don't get help inside the IDE or look into the implementation of methods.
What do I need to add to my build.gradle.kts to include docstrings and sources in the debug version of the .aar I'm publishing locally as a file? The linked gradle documentation from that Android developer page does not mention anything about docstrings or sources at all.
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
}
group = "com.wavelt.libs"
version = "1.0.0"
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes")
}
}
dependencies {
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION))
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("com.google.android.material:material:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test:rules:1.0.2")
}
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
repositories {
maven {
// https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories
url = uri("$buildDir/repository")
}
}
publications {
create<MavenPublication>("debug") {
// Applies the component for the release build variant.
from(components["debug"])
artifactId = "wavelt-android-debug"
artifact("androidJavadocsJar") // Doesn't seem to work
}
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
artifactId = "wavelt-android"
}
}
}
}
While I've read about other devs being able to cram the javadocs into the .aar file, this is not explicitly necessary at all to gain documentation and source code inspection from inside IDEs like Android Studio. In fact, looking at the way a typical java library works, it creates files like:
foo-ver.jar
foo-ver-sources.jar
foo-ver-javadoc.jar
The only difference with an Android library would be having these files:
foo-ver.aar
foo-ver-sources.jar
foo-ver-javadoc.jar
Which means that the sources and javadoc jars can still be copied along the .aar and the IDE will load them. Having said that, the publish example code only creates the .aar file, looking at other questions like this one I was able to modify the script to create the .aar plus the two other .jar packages:
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.library")
kotlin("android")
`maven-publish`
id("org.jetbrains.dokka") version "0.9.17"
}
group = "com.wavelt.libs"
version = "1.0.0"
android {
compileSdkVersion(30)
buildToolsVersion = "30.0.2"
defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes")
}
}
dependencies {
//implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION))
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("com.google.android.material:material:1.3.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("com.android.support.test:runner:1.0.2")
androidTestImplementation("com.android.support.test:rules:1.0.2")
}
tasks.dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
moduleName = rootProject.name
}
val dokkaJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokka)
dependsOn(tasks.dokka)
}
val sourcesJar by tasks.creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles sources JAR"
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
}
artifacts {
archives(sourcesJar)
archives(dokkaJar)
}
// https://developer.android.com/studio/build/maven-publish-plugin
afterEvaluate {
publishing {
repositories {
maven {
// https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:repositories
url = uri("$buildDir/repository")
}
}
publications {
create<MavenPublication>("debug") {
// Applies the component for the release build variant.
from(components["debug"])
artifactId = "wavelt-android-debug"
artifact(sourcesJar)
artifact(dokkaJar)
}
create<MavenPublication>("release") {
// Applies the component for the release build variant.
from(components["release"])
artifactId = "wavelt-android"
}
}
}
}
With these modifications the ./gradlew publish task will generate all files, and despite one of them having .aar they work the same as .jar when copied together into another project.