1

I am developing an android application that requires a Java library application (which I also wrote) to run.

I followed idunnololz guide here to add the project as a java library which seemed to add ok. My java project is called Osmosis and contains 2 packages search and common.

I then tried to reference my project, with Android Studio very helpfully asking if I wish to reference osmosis. This seemed to resolve the error, with import Search.* being added to the top of my android class. However, when I run my application I get the error: package does not exist. Until I click run it shows no errors.

Can anyone give any advice on how to fix this?

I have tried invalidating the caches, cleaning and rebuilding the project

My settings.gradle seems to include the reference:

include ':app', ':osmosis'

and here is my build.gradle

  // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.matt.windowrunner"
        minSdkVersion 21
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.5.87'
}

The errors:

Error:(48, 14) error: package search does not exist
Error:(448, 7) error: cannot find symbol variable Search
Error:(460, 7) error: cannot find symbol variable Search
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Matt Boyle
  • 385
  • 1
  • 6
  • 25

1 Answers1

0

Can anyone give any advice on how to fix this?

Your dependencies closure does not pull in the library. Add compile project(:osmosis) after your other two compile lines in your build.gradle.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for the help. For anyone else who may look at this, the :osmosis needs to be in '' so (':osmosis'). This had now led to a Local path doesn't exist error but I'm guessing that is something else. – Matt Boyle Jan 10 '15 at 21:13
  • Does `compile project` have to be after `testCompile`? – IgorGanapolsky Apr 17 '15 at 05:40
  • 1
    @IgorGanapolsky: I am not aware that the order matters for most things -- I was just trying to provide more specific instructions to help with the edits here. One place where the order *does* matter is in manifest merging. Having `:osmosis` after `play-services` would mean that `play-services` manifest entries would be considered more important than `:osmosis` ones. – CommonsWare Apr 17 '15 at 10:52