icerockdev / moko-template

Template project of a Mobile (Android & iOS) Kotlin MultiPlatform project with the MOKO libraries and modularized architecture
https://moko.icerock.dev/
Apache License 2.0
461 stars 47 forks source link

Adding Android specific maven repository #6

Closed Jaime97 closed 4 years ago

Jaime97 commented 4 years ago

Hello,

This is a question, nos an issue, so you can label as so if you like. I'm trying to add an Android specific dependency and to do so they require to add a new maven repository in the section "repositories" under "allprojects". I'm doing it in the root project "build.gradle.kts" (along with all the others). Then I add the dependencies inside the section "dependencies" of the module "android-app", just like in any other Android project.

The problem is it is giving me an error "Unable to resolve dependency" as if I hadn't added the repository. So, my question is: am I missing something? Is that the correct file to add the repo for an Android specific dependency?

Thanks in advance for all the help

Alex009 commented 4 years ago

hello!

can you show your root and android-app build.gradle.kts files? according to your description everything is done right, i need code to help

Jaime97 commented 4 years ago

Hello Alex, Sorry to take so long to respond. I've tried with another dependency (also requiring a specific maven repository) and it works well, so it must be something else non-related with the project configuration (although I have managed to make the problematic dependency work in an Android project).

I add the files just in case you see something wrong but seeing that the other dependency have worked it is clear that the issue is not related with this project, so you can close it if you like:

The root build.gradle:

plugins {
    id("com.gradle.build-scan") version("2.1")
}

allprojects {
    repositories {
        google()
        maven { url = uri("myWorkingRepo") }
        maven { url = uri("myNonWorkingRepo") }
        jcenter()
        maven { url = uri("https://kotlin.bintray.com/kotlin") }
        maven { url = uri("https://kotlin.bintray.com/kotlinx") }
        maven { url = uri("https://dl.bintray.com/icerockdev/moko") }
        maven { url = uri("https://kotlin.bintray.com/ktor") }
        maven { url = uri("https://dl.bintray.com/aakira/maven") }
    }

    configurations.create("compileClasspath")
}

buildScan {
    termsOfServiceUrl = "https://gradle.com/terms-of-service"
    termsOfServiceAgree = "yes"
}

tasks.register("clean", Delete::class).configure {
    delete(rootProject.buildDir)
}

The android-app one:

plugins {
    id("com.android.application")
    id("kotlin-android")
    id("kotlin-kapt")
    id("dev.icerock.mobile.multiplatform-units")
}

android {
    compileSdkVersion(Versions.Android.compileSdk)

    dataBinding {
        isEnabled = true
    }

    dexOptions {
        javaMaxHeapSize = "2g"
    }

    defaultConfig {
        minSdkVersion(Versions.Android.minSdk)
        targetSdkVersion(Versions.Android.targetSdk)

        applicationId = "org.my.id"

        versionCode = 1
        versionName = "0.1.0"

        vectorDrawables.useSupportLibrary = true
        multiDexEnabled = true

        val url = "https://newsapi.org/v2/"
        buildConfigField("String", "BASE_URL", "\"$url\"")
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
        }
        getByName("debug") {
            isDebuggable = true
            applicationIdSuffix = ".debug"
        }
    }

    packagingOptions {
        exclude("META-INF/*.kotlin_module")
    }
}

dependencies {
    implementation(Deps.Libs.Android.kotlinStdLib.name)

    implementation(Deps.Libs.Android.appCompat.name)
    implementation(Deps.Libs.Android.material.name)
    implementation(Deps.Libs.Android.recyclerView.name)

    // I have tried adding it through Deps.Libs and also directly
    implementation ("myWorkingDependency")
    implementation ("myNonWorkingDependency")

   // Multidex is required, could this be related?
    implementation(Deps.Libs.Android.multidex.name)

    implementation(Deps.Libs.MultiPlatform.napier.android!!)

    implementation(project(":mpp-library"))
}

multiplatformUnits {
    classesPackage = "org.my.id"
    dataBindingPackage = "org.my.id"
    layoutsSourceSet = "main"
}

Thanks for the help!

Alex009 commented 4 years ago

Multidex is required, could this be related? no, we use multidex in own apps and not see any problems with dependencies

about config - seems ok. to more help i need dependency repo and name, to test it on local project :)

also you can try run ./gradlew build --info and check what reason show gradle about in dependency and where try search

Jaime97 commented 4 years ago

Hi Alex, Sorry to take so long to respond, the Dependency is this one. Although it is a private library they say it can be tested without any license so I think we both should be able to try it locally.

Alex009 commented 4 years ago

hi! i try this lib, gradle show error 403 when i try to attach library. Follow by docs:

PDFTron SDK for Android is hosted on a private Maven repository in Amazon S3, so an access token is required to download it. The project only communicates with Amazon S3 in order to download PDFTron SDK for Android. Otherwise, no other communication between your environment and Amazon S3 (or any other external service) is required. If you prefer not to use Amazon S3, you can find an alternative approach here.

i think you should get from PDFTron support some config, like described in gradle docs - https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:s3-repositories

Jaime97 commented 4 years ago

Okay Alex, thanks for the help! I see it is something specific to this library and not related yo this project.

Jaime97 commented 4 years ago

Hello,

Sorry to bother you again with this problem but I'm starting to see that it may be something specific of this project. I have been in contact with the PDFTron support, and here's what they have said:

Thanks for contacting us. In this case, the message you are seeing is due to the project looking for a tools-7.1.0.module file file, however in our maven repository we currently do not support this (currently we have .pom files). ​ I've also tried integrating PDFTron using a separate project with Kotlin Gradle DSL support and I was able to integrate via Gradle successfully (for reference, here is a random sample app I tried), so it seems like something specific to the MOKO project.

Additionally, PDFTron no longer requires any access tokens for Gradle integration using our Maven repository in S3. This is a mistake in the documentation and it will be removed.

It seems they don't require the tokens anymore so the 403 appears to be caused by another reason. Does any of this ring a bell for you?

Thanks for the help

Alex009 commented 4 years ago

I see...please remove from settings.gradle.kts line: enableFeaturePreview("GRADLE_METADATA") it's not required for mpp dependency resolution (only for publication of mpp libs) and try search .module first, but you want search .pom

Jaime97 commented 4 years ago

Okay, so finally it has worked. Thanks for all the help!