5

In Android Studio I have an Android project which contains an module called go setup with Gradle to be an Android library. It contains a single Java package called com.nwoods.go. For the sake of this Stack Overflow submission, it contains a class called FooBar

Inside the same Android project, I have an application module called ugurdemo1 which has a MainActivity class in the package com.nwoods.ugurdemo1.

Android Studio I have modified the project structure for the module ugurdemo1 to depend on the library go at compile time. In ugurdemo1's MainActivity, I'd like to reference and use the class FooBar from go. To do this, I prefaced the class with a typical Java import statement:

   import com.nwoods.go.FooBar;
   ... 
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FooBar myFooBarObject = null; 

Android Studio still can not resolve the symbol for FooBar after doing a clean rebuild of my sources. Similar questions on Stack Overflow were resolved by editing the compile time settings in the Dependency dialog but again that does not work. If it is of any help, I am currently running Android Studio IO Preview (0.3.6)

deadboy
  • 849
  • 2
  • 9
  • 28
  • 1
    Facing the same problem but my project builds fine via Gradle so it's an AS issue that's still unsolved in 0.8.4. – jonalmeida Jul 30 '14 at 10:41

2 Answers2

8

It sounds like you've done the right thing, but to confirm, here's a screenshot of a Project Structure dependencies panel that lets you set module dependencies in Gradle:

Screenshot of Android Studio Project Structure dialog

This module already has dependencies on two libraries retrieved via Maven-style imports, and it also as a dependency on the Foo module. To add a new dependency, you click on the + button at the bottom and choose a dependency type (shown).

You can also edit your Gradle build files by hand. In my example, there's a build.gradle file in the "two" module's directory. It has a dependencies block that looks like this:

dependencies {
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:appcompat-v7:+'
    compile project(':Foo')
}

You can add further compile project lines to add new module dependencies; use a colon-delimited syntax to provide the position of the module relative to the project's root directory.

If you edit the build.gradle file by hand, click on the "Sync Project with Gradle Files" button in the toolbar when you're done to make Android Studio re-read the file and pick up your changes.

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
2

The problem may not be your project but a bug in Android Studio itself that's being tracked here: https://code.google.com/p/android/issues/detail?id=65915

The "fix" is to delete the settings.gradle from all modules except the root project directory.

For example, in my situation, my project structure looks like this:

build.gradle
settings.gradle
library_module:
   build.gradle
   settings.gradle
      library:
         build.gradle
         settings.gradle
android_app:
   settings.gradle
   build.gradle

After deleting, the structure looked like this:

build.gradle
settings.gradle
library_module:
   build.gradle
      library:
         build.gradle
android_app:
   build.gradle

Cheers

jonalmeida
  • 1,206
  • 1
  • 9
  • 24
  • 1
    Thank you for this comment. We ended changing tools at the time since we didn't have time to wait around/deal with buggy development tools. But for what it's worth, it seems that it has been patched as of March 2015 https://code.google.com/p/android/issues/detail?id=65915#c29 – deadboy May 18 '15 at 15:54