I am using Android studio but this may be a general Intellij question (I'm used to eclipse). This seems like it should be super simple, but I can't figure it out.
I want to be able to run either module in my project independently, which is from what I understand the purpose of a module. This has worked fine until now when I want to call code from my "app" module in my "testmodule" module. Android Studio lets me import the code I need with no problems until I try to build the module. Then I get the expected "package not found" error. So then I try adding this in my "testmodule" build.gradle:
main.java.srcDirs '../app/src/main/java'
This causes two package import statements in my "app" module to fail. One of the failing packages is the package defined in my "app" manifest and the other is specified in my "app" build.gradle
sourceSets {
main.java.srcDirs += '../../connectorAPI/trunk/src'
}
I also tried to make one module depend on another but from what I've read in stack overflow (and the vague Android Studio error) one module must be a library file. This obviously doesn't work since I want to be able to run either. I would love to just copy the code I need but then I'd need to change both every time in version control, which is a nightmare.
In eclipse all you have to do is right click and link source. I can't imagine this is impossible or even out of the ordinary, so I must be missing something simple... can someone please help me out?
build.gradle testmodule
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.XXXXX.testmodule"
minSdkVersion 15
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.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
}
build.gradle app
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.XX.XXX.XXX.XXX"
minSdkVersion 15
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
sourceSets {
main.java.srcDirs += '../../connectorAPI/trunk/src'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:+'
// Add the ArcGIS Android 10.2.5 API
compile 'com.esri.arcgis.android:arcgis-android:10.2.5'
compile 'com.googlecode.json-simple:json-simple:1.1'
}
I might be late by a few years but here is what I would do : Declare both modules as library, and create another two as application. Then you can easily import the two libriaries while still having two applications, if that is what you want.
As for the duplicate dependency issue that will arise, you can just add an exclude statement in the build.gradle respectively.
Related
I am trying to import pd-for-android into my project as a gradle dependancy as per the instructions on pd-for-android's githubpage (i.e. make sure jcenter() is in the top level repositories in build.gradle, then add compile 'org.puredata.android:pd-core:1.0.1' to your dependancies in the app build.gradle)
I followed these instructions but I cannot see the library downloading into my external libraries. Is there something else i need to do in order to get this working?
here's my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
defaultConfig {
...
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
...
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.2.1'
compile 'io.reactivex:rxjava:+'
compile 'io.reactivex:rxandroid:+'
compile 'org.puredata.android:pd-core:1.0.1'
}
Check if It's inside app\build\intermediates\exploded-aar\
If you have there the library, you shouldn't have any problem to use it.
Does it show up correctly as dependency when you click File->Project Structure and then on the dependencies tab in Android Studio?
if not, have you tried to add it there via the "+" Button?
I am trying to add this dependency https://github.com/hoang8f/android-flat-button in to my android studio project and I am getting
Error:(26, 13) Failed to resolve: info.hoang8f:fbutton:1.0.5
I am able to add google play services dependency easily without any problems.
Below is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.planner"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'info.hoang8f:fbutton:1.0.5'
}
Solutions tried:- 1.)Gradle is working in online mode not offline.
2.)Cleaned and builded/rebuilded the project.
3.) Changed to
repositories {
mavenCentral()
}
in my root gradle file
4.) Tools->android->Sync Project with gradle files
Still no luck in making it work.
P.S.:- Not that it effects the questions, I faced the same problem while trying to add parse sdk via gradle, so I added the jar file independently.
add
repositories {
mavenCentral()
}
include android tag
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.planner"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
mavenCentral()
}}
Please try this. Add fbutton-1.0.5.aar file into your lib folder.
repositories {
flatDir {
dirs 'libs'
}
}
Add aar file into dependencies.
dependencies {
compile(name:'ARFile', ext:'aar')
}
Did you noticed how looks like build.gradle of a demo project?
https://github.com/hoang8f/android-flat-button/blob/master/demo/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 2
versionName "1.1"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
} }
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.larswerkman:HoloColorPicker:1.4'
compile fileTree(dir: 'libs', include: ['*.jar']) // compile project(':library')
compile 'info.hoang8f:fbutton:1.0.5'
}
Check if you're not missing something in your Gradle file or you put something wrong
EDIT: I've put whole your build.gradle file into my new project and it's work fine.
If rebuilding not help, create a new clean project and put this build.gradle. Tell me is it works with new project.
EDIT2:
In your project you have two build.gradle change the second one to
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
jcenter()
}
}
I had the same problem.
Invalidate cache and restart your android studio. Then sync gradle.
I cloned the project and used "demo" module to test the lib. The lib that you needed was downloaded successfully and this is expected, because it exists in the maven repo
The only point I noticed - probably you may have problems with gradle, because there's runProguard command, that is not used in gradle no more.
So you may just delete it or change to minifyEnabled false.
After doing this, demo project assembles successfully
I am having trouble in importing and using the volley library in the android studio 1.3.0 project. I have followed tutorials online to import the volley from git into the project directory.
Now, I am having trouble in making it work with the project. I am unable to build it using instructions online.
Error it generates is:
Error:(23, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'Hrup' may be using a version of Gradle that does not contain the method.
Gradle settingsThe build file may be missing a Gradle plugin.
Apply Gradle plugin
I have included files like, build.gradle for all folder, and settings.gradle
Build.gradle (volley)
// NOTE: The only changes that belong in this file are the definitions
// of tool versions (gradle plugin, compile SDK, build tools), so that
// Volley can be built via gradle as a standalone project.
//
// Any other changes to the build config belong in rules.gradle, which
// is used by projects that depend on Volley but define their own
// tools versions across all dependencies to ensure a consistent build.
//
// Most users should just add this line to settings.gradle:
// include(":volley")
//
// If you have a more complicated Gradle setup you can choose to use
// this instead:
// include(":volley")
// project(':volley').buildFileName = 'rules.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
compile project (':volley')
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion = '22.0.1'
}
apply from: 'rules.gradle'
dependencies {
}
Build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.bali.hrup"
minSdkVersion 14
targetSdkVersion 23
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.android.support:appcompat-v7:23.0.1'
}
Build.gradle(Hrup{my project name})
// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Settings.gradle
include ':app'
include ':volley'
Just a Small Change, Edit the file build.gradle(app), not the build.gradle(volley)
Just add a single line
compile project (':volley')
Final file(build.gradle(app)) will look like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.bali.hrup"
minSdkVersion 14
targetSdkVersion 23
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.android.support:appcompat-v7:23.0.1'
compile project (':volley')
}
Android Studio cannot find the necessary YouTube classes in my application. I'm recycling some code of a previous project. In the previous project I just imported the jar file provided by google. But I want to learn a better way using gradle. I've used gradle before with success. Its awesome when it works. I've been able to add dependencies using gradle before. But for some reason I can't get a google lib to download or activate or whatever it needs to do so that my IDE can find all these missing youtube symbols. I've done the usual syncing with gradle and rebuilding and cleaning and all that but it hasn't helped.
Here is my build.gradle file:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "dayspringwesleyan.org.dayspringwesleyanchurch"
minSdkVersion 10
targetSdkVersion 22
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.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev141-1.20.0'
compile 'com.koushikdutta.ion:ion:2.1.6'
}
I'm trying to compile an App utilising a separate App as a dependency but when I compile referencing modules from this library I see several "error:package does not exist" and "error:cannot find symbol class" messages from graddle. The following are my two build files.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'AndroidManifest.xml'
exclude 'resources.arsc'
exclude 'classes.dex'
}
}
dependencies {
repositories {
mavenCentral()
}
compile 'com.android.support:support-v4:+'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.google.android.gms:play-services:+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:+'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'se.emilsjolander:stickylistheaders:2.+'
compile 'com.googlecode.libphonenumber:libphonenumber:+'
compile files('libs/crashlytics.jar')
compile files('libs/httpclient-4.2.3.jar')
compile files('libs/libphonenumber-5.9.jar')
compile files('libs/mobileservices-0.2.0-javadoc.jar')
compile files('libs/mobileservices-0.2.0.jar')
compile files('libs/stringtotime-1.0.4.jar')
compile files('libs/urbanairship-lib-2.0.2.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
compile files('libs/FlurryAnalytics-4.0.0.jar')
compile 'com.squareup.picasso:picasso:2.3.3'
compile project(':wheel')
}
Dependency gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "kankan.wheel"
minSdkVersion 5
targetSdkVersion 7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Can anyone help/experienced this before? Android Studio does not highlight any issues in the class and I can ctrl+click through to the packages referenced which seems to mean it is set up correctly...
Thanks!
The buildTypes section should not be in library build.gradle file.
You cannot have two gradle scripts using the com.android.application plugin at the same time. Change the dependency project to apply the 'library' plugin.
If that doesn't do it, change the targetSdkVersion of your dependency to that of your core project.
If you are using a Android library module as a dependency (i.e. mylib), then make sure in your app.iml file that you see the following line toward the end of the file:
<orderEntry type="module" module-name="mylib" exported="" />
Try changing min and target sdk to 11 and 19 according in dependency gradle-default config.
I had a similar issue posted here
But I got it resolved using #Doge's suggestion,
I converted the dependency android project to library project.
Thanks.