Android Studio Gradle import module Build error

I am trying to add a directory as a dependency in Android Studio (GameBaseUtils). I saw other SO answers, just sending the correct gradle configuration for their specific problem, however I don't understand how I can adapt my answers to my situation.

Here is what I did:

Step One: File-> Import Module → Go to the directory and select it.

Step two: File-> Project Structure-> Modules-> Select my application-> Dependencies-> Add the module to the dependency of my project.

Now my code does not have red lines indicating an error importing the module. However, when choosing an assembly, I get the following errors:

Gradle: package com.google.example.games.basegameutils does not exist Gradle: cannot find symbol class BaseGameActivity Gradle: cannot find symbol variable super ... 

Here is the build.gradle file for my application

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.4' } } apply plugin: 'android' dependencies { compile files('libs/android-support-v4.jar') } android { compileSdkVersion 17 buildToolsVersion "17.0.0" defaultConfig { minSdkVersion 8 targetSdkVersion 17 } } 

How can I import this external library correctly and explain how and why your solution works?

+8
android android-studio gradle
source share
2 answers

So this is how I solved my problem:

instead of adding

 dependencies { compile files('libs/android-support-v4.jar') compile project(':Module') } 

You need to write:

 dependencies { compile files('libs/android-support-v4.jar', '../Module') } 

2 points say that the module (or directory) can be found in 1 directory above the actual one. therefore, if you want to access a module that contains 2 directories above, you just need to write: '../../ModuleName'

You must add the modules manually in build.gradle, because Android Studio is still under development and has not completed the user interface for editing the project structure.

If this does not solve your problem, try doing this: (I would recommend this method. Here's how I do it)

Examplestructure:

  • Project

    • libraries (regular folder)
      • Module 2
    • Module1

settings.gradle

 include ':Module1', ':libraries:Module2' 

build.gradle (Module1)

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android' dependencies { compile project(':libraries:Module2') } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 8 targetSdkVersion 11 } } 

build.gradle (Module2)

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android-library' dependencies { compile 'com.android.support:support-v4:18.0.0' } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 8 targetSdkVersion 11 } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] res.srcDirs = ['res'] } } } 

Now it will work well. To make everything work 100%, follow these steps:

  • delete .idea folder
  • delete all *.iml files
  • Restart Android Studio and click Import Project
  • Select directory with gradle project
  • Import project from external model > gradle> next> finish

With these steps, everything should work well. If there is any problem, just tell me :)

+8
source share

Do not add modules through the Studio interface. Always make changes directly to build.gradle and then reimport in Studio.

Also, update the plugin dependency to com.android.tools.build: gradle: 0.4. + To get the latest version 0.4. *.

-one
source share

All Articles