0

I'm currently trying to move an old project from eclipse to Android Studio. The project contains a "core module" (contains a lot of network stuff), an Android app and a Java PC application which both include the core module to communicate with each other. Each app and the core have a own repo.

When using eclipse the app, the PC applicaton and the core were three independet eclipse projects in the same workspace and the two apps where depending on the core project.

I successfully moved the Android app to Android Studio and the core to IntelliJ with gradle. I now try to tell Android Studio to compile the core when building the app. My file structure looks like this:

GitHub
------\ AndroidApp
----------------\ build.gradle
----------------\ settings.gradle
----------------\ app
---------------------\ build.grale
------\ NetworkCore
----------------\ build.gradle
----------------\ settings.gradle

AndroidApp/build.gradle

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

AndroidApp/settings.gradle

include ':app', 'core'
project(':core').projectDir = new File('../NetworkCore')

AndroidApp/app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "xxxxxxxxxxx"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile project(':core')
}

NetworkCore/build.gradle

group 'xxxxxxxxxx'
version '1.0-SNAPSHOT'

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

NetworkCore/settings.gradle

rootProject.name = 'xxxxxxx'

The Issue

Android Studio detects core as module and properly lists all files in the left sidebar. But when compiling Android Studio is not able to find the classes from core and sometime even the classes from the app module (like Fragment classes etc.).

What am I doing wrong? Thank you very much in advance :)

crysxd
  • 3,177
  • 20
  • 32
  • Have u imported your module properly ? and have u added dependency in your android app for the core module ? Why you have added testcompile as a dependency for your android app ? test compile is dependent to core ..make core dependent to your app – Chiradeep Nov 20 '15 at 14:57

1 Answers1

1

Are you missing colon in your AndroidApp/settings.gradle file?

include ':app', ':core'
project(':core').projectDir = new File('../NetworkCore')
Suhas
  • 1,451
  • 14
  • 22
  • I copied this from this answer: http://stackoverflow.com/a/24978161/4021947 I already tried it with and without the colon, it seems to make no difference at all – crysxd Nov 20 '15 at 15:04
  • May be this [link](http://stackoverflow.com/questions/17479076/android-studio-add-external-project-to-build-gradle) can help you. – Suhas Nov 20 '15 at 15:05
  • Fixed it! You were right, but there were two other problems. First i had to add sourceCompatibility = 1.7 to NetworkCore/build.gradle as I was using Java 1.8 which is not compatible with android to build it and there was an import error in my file structure I had not recognized...I spend like 2 hours on this and it was sooo simple... – crysxd Nov 20 '15 at 15:23
  • 1
    Glad I could be of help :) – Suhas Nov 20 '15 at 18:04