Create a Github library mix of jvm and Kotlin multiplatform - kotlin

I am trying to build an Android Library and I have the following:
Github Repo for the library
Library 1: Kotlin native/multiplatform code that can compile to Android and iOS
Library 2: Kotlin/JVM code dependent on Library 1
Example App: App using Library 2 and Library 1
Personal Android Project
Dependent on the Github Library above
On my personal project I only have:
implementation 'com.github.username:myrepo:0.5'
Issues
The private Android project is loading android library (Library 2) but the multiplatform kotlin models and functions (Library 1) are not accessible.
Note that the example app of the library is working fine. I suspect that the jitpack.io is not publishing the artifacts correctly. Any idea on how to troubleshoot this? Is there anything that should be done to the gradle files to solve the problem?
I would like to have the multiplatform library published alone. I tried to access it from a multiplatform Kotlin module but I am getting "Unable to resolve dependencies". This is what I was trying:
implementation 'com.github.username.myrepo:library1_moduleName:0.1'
Gradle for Library 1 multiplatform:
plugins {
kotlin("multiplatform")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "library1"
freeCompilerArgs.add("-Xobjc-generics")
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText(
"#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$#\n"
)
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
Gradle for library 2
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api project(":library1")
}

I suggest you change your build.gradle configuration for targeting android/ Change it to
plugins {
kotlin("multiplatform")
id("com.android.library")
id("maven-publish")
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "library1"
freeCompilerArgs.add("-Xobjc-generics")
}
}
}
// jvm("android")
android {
publishLibraryVariants("release")
}
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText(
"#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$#\n"
)
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
create an AndroidManifest.xml file for library1 under src/main/AndroidManifest.xml
<manifest package="library1"/>
you can now push your projet to github, create a tag and wait for jitpack to do its magic
When you want to use it in library2, under the dependencies section, just add
implementation 'com.github.username.myrepo:library1-android:0.1' //for android

Think you may need to enable meta-data for the multi-platform library; in settings.gradle:
enableFeaturePreview('GRADLE_METADATA')
As well as configuring the library for Maven (it is unclear how you publish it to GitHub, as the build.gradle does not feature any of that as automation). Even when publishing it to GitHub instead of mavenLocal(), it likely needs to provide some kind of meta-data... as "Unable to resolve dependencies" might hint for, assuming that it exists under the referenced package name.
apply plugin: 'maven-publish'
group 'com.github.username'
version '1.0.0'
Configuration api is merely good for dependencies, which are being referenced by multiple modules; everything else (any single occurance) should be implementation. I mean, I find the library 2 build.gradle confusing, because on top it reads maven { url 'https://jitpack.io' } (without actually referencing a remote dependency) and then later it reads api project(":library1") (which defintely is a local dependency).

Related

(KotlinSourceSet with name 'androidMain' not found.) How can I add android as a build target to a Kotlin Multiplatform project

I am trying to add android() as a build target to a Kotlin Multiplatform library so that I can add a specific library for the android target. All the other targets (jvm, linux, ios) work fine, but android seems to have issues, because the KotlinSourceSet is not being create like the others.
That's where I get the error:
KotlinSourceSet with name 'androidMain' not found.
I wonder, do I have to add the SourceSet manually? Am I missing some crucial build step?
Here is my gradle.build.kts
plugins {
id("maven-publish")
kotlin("multiplatform") version "1.8.0"
}
buildscript {
repositories {
google()
}
dependencies {
classpath ("com.android.tools.build:gradle:4.2.2")
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
}
}
group = "zzz.xxxx"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
kotlin {
jvm()
linuxX64("linux")
ios()
android()
sourceSets {
val commonMain by getting {
dependencies {
implementation("...")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting {
dependencies {
implementation("...")
}
}
val androidMain by getting {
dependencies {
implementation ("...")
}
}
val jvmTest by getting
}
}
I tried adding a androidMain folder, but it is not getting recognized as a KotlinSourceSet. Non of the resources online seem to help either.
To add android as a build target your need to setup android-gradle-plugin first.
With example setting of android plugin gradle.build.kts will be:
plugins {
id("maven-publish")
kotlin("multiplatform") version "1.8.0"
id("com.android.library") version "7.3.0" // (1) add plugin
}
//...
// (2) setup plugin
android {
compileSdk = 33
defaultConfig {
minSdk = 24
multiDexEnabled = true
}
sourceSets {
getByName("main") {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
}
}
}
UPDATE
Before you are adding Android Gradle plugin:
Check that Google Maven repository is listed in your settings.gradle(.kts) file
Check the Android Gradle plugin is added to the project build.gradle(.kts) file
Check the Android Gradle plugin is compatible with your Gradle version

Kotlin Multiplatform Mobile: Project already has a CocoaPods dependency with name SDWebImage

I have created a demo project to integrate cocoapods into the KMM project. I have followed this link from the official website. At step 3 while reimporting the project, I am receiving the following error.
Project already has a CocoaPods dependency with name SDWebImage , after which I am unable to even import this lib in KMM.
Can anyone please help with this?
Update: Adding build.gradle.kts
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("native.cocoapods")
}
// CocoaPods requires the podspec to have a version.
version = "1.0"
kotlin {
android()
ios {
cocoapods {
// Configure fields required by CocoaPods.
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
pod("SDWebImage")
// You can change the name of the produced framework.
// By default, it is the name of the Gradle project.
frameworkName = "shared"
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.1")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13")
}
}
val iosMain by getting
val iosTest by getting
}
}
android {
compileSdkVersion(29)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
}
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
When you’re using cocoapods plugin you don’t need to manually declare packForXcode target, maybe that’s the problem. Try to remove everything after val packForXcode
cocoapods section should be inside kotlin, not inside ios

Kotlin multiplatform cannot resolved references while gradle sync succeeds

When I compile my kotlin multiplatform project I get Unresolved reference on stuffs that I use in the common module. But the gradle synchronisation works fine. You can found my project here
In details:
I followed the tutorial from Jetbrain to build a mobile multiplatform project. Everything works fine.
Then I implemented inside the common module a ktor client to request an api (jsonplaceholder). I added all the required dependencies and everything seems good. All references are resolved, I have no errors.
But when I compile my project with make Project then all the dependencies added to get ktor and so on cannot be resolved.
I guess I have a problem with the configuration of my project, when I run ./gradlew androidDependencies it seems that there is a problem with SharedCode since it is sometimes marked in the command´s output as \--- :SharedCode.
The build.gradle for the project is:
buildscript {
ext.kotlin_version = '1.3.71'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0-rc01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The build.gradle.kts for the common SharedCode module is:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
val serializationVersion = "0.20.0"
val ktorVersion = "1.3.2"
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-json:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")//Kotlinxserializer
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText("#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$#\n")
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
And the build.gradle for the android app is:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.mpp.mpptest"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(':SharedCode')
}
Do you know what I am doing wrong?
I read Building Multiplatform Projects with Gradle but it did not help.
The only working project that I found is from KaMPKit. I have set my build.gradle(.kts) files as they are in KaMPKit (see the branch Set_build_gradle_as_KaMPKit) but the `unresolved references´ problem remains.
I fixed my problem. The error came because I did not declare the plugin android.lybrary.
Even if it is not necessary to fix the problem, I have decided to switch my build.gradle files to kotlin DLS, I rewrote all the build.gradle and I made the following changes for the shared module:
I created a AndroidManifest.xml
I added the com.android.library plugins
I added a block android
At the end the build.gradle.kts for the shared module looks like this:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("kotlinx-serialization")
id("com.android.library")
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(Versions.min_sdk)
targetSdkVersion(Versions.target_sdk)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "SharedCode"
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation(kotlin("stdlib-common", Versions.kotlin))
implementation(Deps.Ktor.commonCore)
implementation(Deps.Ktor.commonJson)
implementation(Deps.Coroutines.common)
implementation(Deps.Ktor.commonSerialization)
}
sourceSets["androidMain"].dependencies {
implementation(kotlin("stdlib", Versions.kotlin))
implementation(Deps.Coroutines.jdk)
implementation(Deps.Ktor.androidSerialization)
}
sourceSets["iosMain"].dependencies {
implementation(Deps.Ktor.iosSerialization)
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText("#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$#\n")
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
All dependency version numbers come from a Dependencies.kt files (see KaMPKit)
All dependencies are now resolved.

Can't import dependencies for Kotlin multi platform common

I am trying out Kotlin multi-platform and trying to setup all my dependencies for it. Starting with commonMain
I am trying to add Koin and Ktor dependencies to the common portion but I cant seem to be able to use any of them.
This is my Gradle script
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
}
repositories {
google()
jcenter()
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
applicationId 'org.jetbrains.kotlin.mpp_app_android'
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.koin:koin-android:2.0.1'
implementation 'org.koin:koin-androidx-viewmodel:2.0.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
kotlin {
android("android")
// This is for iPhone emulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
iosX64("ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation 'org.koin:koin-ktor:2.0.1'
implementation 'org.koin:koin-core:2.0.1'
// HTTP
implementation "io.ktor:ktor-client-core:1.2.6"
implementation "io.ktor:ktor-client-json:1.2.6"
implementation "io.ktor:ktor-client-serialization:1.2.6"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.2.1"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
implementation kotlin('stdlib')
}
}
androidTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
}
iosTest {
}
}
}
// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
def target = project.findProperty('kotlin.target') ?: 'ios'
dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask
doLast {
def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
def targetDir = getProperty('configuration.build.dir')
copy {
from srcFile.parent
into targetDir
include 'app.framework/**'
include 'app.framework.dSYM'
}
}
}
In the Sample.kt file that was generated when I created the project I tried to setup Koin in the main method
fun main() {
startKoin {
// declare modules
modules(myModule)
}
println(hello())
}
but startKoin cannot be resolved.
I cleaned/rebuilt the project, did a gradle sync and still cant import koin or any other dependency so what am I missing
Koin is not multiplatform capable. We have [multiplatform forks][1], but would need to chat about which to use and what version. We're still discussing multiplatform strategy.
Ktor's dependencies are more complex than that. See below. I removed your other dependencies for clarity, but you should leave them obviously :)
sourceSets {
commonMain {
dependencies {
implementation "io.ktor:ktor-client-core:1.2.6"
implementation "io.ktor:ktor-client-json:1.2.6"
implementation "io.ktor:ktor-client-serialization:1.2.6"
}
}
androidMain {
dependencies {
implementation "io.ktor:ktor-client-core-jvm:1.2.6"
implementation "io.ktor:ktor-client-json-jvm:1.2.6"
implementation "io.ktor:ktor-client-serialization-jvm:1.2.6"
}
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:1.2.6"
implementation "io.ktor:ktor-client-core-native:1.2.6"
implementation "io.ktor:ktor-client-json-native:1.2.6"
implementation "io.ktor:ktor-client-serialization-native:1.2.6"
}
}
}
[1]: https://github.com/kpgalligan/koin/tree/kpg/khan

double espresso test with gradle - empty test suite

I'm trying to use espresso to test my aplication. As I found in other postes I shall use double espresso insted of pure espresso with gradle. Doulbe espresso can be found here: https://github.com/JakeWharton/double-espresso.
I configured a run configuration like this: http://wiki.android-test-kit.googlecode.com/git/android-studio-new-run-configuration.png. When I execute it, after a while it says Empty Test Suite
I created the following test class in androidTest/java directory:
package com.myapp.mobileapp.test.ui;
#LargeTest
public class LoginTest extends ActivityInstrumentationTestCase2<LoginActivity> {
public LoginTest(Class<LoginActivity> activityClass) {
super(activityClass);
}
#Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
#SmallTest
public void testLogin() {
onView(withId(R.id.buttonLogin))
.perform(click());
assertTrue(true);
}
}
My project has a top project that has the apk project and the facebook library project.
The build file for the top project is the following:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
the build file for the apk project is the following:
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "19.1.0"
// https://code.google.com/p/android/issues/detail?id=71147
useOldManifestMerger true
defaultConfig {
applicationId "com.myapp.mobileapp"
minSdkVersion 14
targetSdkVersion 18
testApplicationId "com.myapp.mobileapp.test"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- rules.txt'
}
debug {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
// OTHERS
compile 'com.android.support:support-v4:18.0.0'
compile('com.google.code.gson:gson:2.2.4')
// GOOGLE PLAY SERVICES
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:3.2.65'
// FACEBOOK
compile project(':facebookSDK')
// CHAT LIBRARY
compile files('libs/asmack-android-18-0.8.10.jar')
// GOOGLE ANALITICS
compile files('libs/libGoogleAnalyticsServices.jar')
// ORMLITE
compile 'com.j256.ormlite:ormlite-core:4.41'
compile 'com.j256.ormlite:ormlite-android:4.41'
// ROBOSPICE
compile('com.octo.android.robospice:robospice:1.4.6') {
exclude module: 'support-v4'
}
compile('com.octo.android.robospice:robospice-spring-android:1.4.6') {
exclude module: 'support-v4'
}
compile('org.codehaus.jackson:jackson-mapper-asl:1.9.11')
// LOGGING
compile files('libs/slf4j-api-1.7.5.jar')
compile files('libs/logback-android-1.0.10-2.jar')
// VOLLEY
compile files('libs/volley.jar')
// TESTING TOOLS
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3')
}
I´m using the following tools:
Android Studio 0.6.1
(built in gradle in android studio) gradlew --version
Gradle 1.10
Build time:2013-12-17 09:28:15 UTC
Build number:none
Revision:36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy:1.8.6
Ant:Apache Ant(TM) version 1.9.2
Ivy:2.2.0
JVM:1.8.0_05 (Oracle Corporation 25.5-b02)
OS:Windows 8.1 6.3 amd64
You are probably getting an exception, so check the logs.
The constructor needs to be like this:
public LoginTest() {
super(LoginActivity.class);
}
Similar question and answer:
Espresso testing android