I create a project on IntelliJ IDEA using Gradle and I'm trying to add AndroidSlidingUpPanel to it (https://github.com/umano/AndroidSlidingUpPanel).
What exactly do I have to do to configure it?
I have the following folder structure:
RootFolder
|_libraries
|_ AndroidSlidingUpPanel
|_ library
|_ build.gradle
|_ settings.gradle
|_ build.gradle
|_app
|_ build.gradle
|_ settings.gradle
|_ build.gradle
The files are like this:
RootFolder/settings.gradle
include ':app'
include ':libraries:AndroidSlidingUpPanel:library'
RootFolder/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
RootFolder/libraries/AndroidSlidingUpPanel/settings.gradle
include ':library'
include ':demo'
RootFolder/libraries/AndroidSlidingUpPanel/build.gradle
allprojects {
group 'com.sothree.slidinguppanel'
version '1.0.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
}
dependencies {
repositories {
mavenCentral()
}
}
}
RootFolder/libraries/AndroidSlidingUpPanel/library/build.gradle
apply plugin: 'android-library'
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
RootFolder/app/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.2"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
You aren't clear about what build errors you may be having or what your exact question is, though since you haven't got a dependency to SlidingUpPanel in your app/build.gradle, the question is how to include it?
If so, the first thing to bear in mind is that a project can't have more than one settings.gradle. To be more precise, it only looks in the root folder for it and uses it if it's there. So the settings.gradle in RootFolder/libraries/AndroidSlidingUpPanel/ will be ignored. It looks like you've properly set up an include to the SlidingUpPanel library in RootFolder/settings.gradle, so that's good:
include ':libraries:AndroidSlidingUpPanel:library'
to include a dependency on it in your app, you use a compile project statement and give it the same path:
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile project(':libraries:AndroidSlidingUpPanel:library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
If you're using Android Studio (it should also work with Gradle-based projects in IntelliJ Community Edition), you can set up dependencies on modules from the Project Structure dialog via Modules > Your module > Dependencies > + > Module dependency:
If you've added the module to your settings.gradle file as you already have and have synced up your project to the Gradle files, then the SlidingUpPanel module should appear in the Project view in the IDE and should appear as a module choice in that dependency list.
Related
I have a project in Eclipse with gradlle.
I want to run the project on a physica device, but I do not see the option.
I select run tab, project just runs gradle.
Check below build.gradle file
apply plugin: 'java'
repositories {
jcenter()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile files ('libs/twitter4j-core-4.0.4.jar')
compile files ('libs/gson-2.2.2.jar')
compile files ('libs/agilio_rtmp-debug.jar')
compile files ('libs/facebook-android-sdk-4.14.1.jar')
compile files ('libs/agilio_rtmp-debug.jar')
}
When I select run:
I want to run the project on a physical device.
The task you want is app:installDebug, but that is assuming you have the correct project structure.
Since it isn't clear what the structure your project has, here is the recommended structure from the Android Gradle documentation.
settings.gradle
build.gradle # Top-level
app/ # A module named 'app'
build.gradle # Module-level
libs/
library-1.jar
library-2.jar
...
src/main/
AndroidManifest.xml
java/ # application package in here, then Java files in that
res/
This is the settings.gradle
include ':app'
Here is a top-level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
Then, the module build.gradle with adjustments for your dependencies.
Most importantly - The top line here tells Gradle this is an android app, not a java app. This means you can run the various Android-related Gradle tasks like installDebug, which is the one you are looking for.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "xxxxxxxx"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
// Variables to keep libraries consistent
supportLibrary = '23+'
// Support Libraries dependencies
supportDependencies = [
design : "com.android.support:design:${supportLibrary}",
appCompatV7 : "com.android.support:appcompat-v7:${supportLibrary}"
]
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
// This line already compiles all jar files in the libs/ directory
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// recommended
compile supportDependencies.design
}
The file google-sevices.json is missing from module root folder even the file is in the app directory. My gradle version is 2.10. I have spent most of my time to solve this issue but still I cannot resolve the issue.
Project-level 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:2.1.0'
classpath 'com.google.gms:google-services:2.1.0' //this is the latest version
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
App-Level gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myairticket.testpush3"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { res.srcDirs = \['src/main/res', 'src/main/jsonfiles'\] } }
}
dependencies {
compile fileTree(dir: 'libs', include: \['*.jar'\])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
}
apply plugin:'com.google.gms.google-services
I would double check that it's in your app folder and not in the /res folder. If you dragged the file in to Android Studio and you were in the Android view instead of Project Files, there's a good chance it got copied into the wrong directory.
On my home desktop (Ubuntu) my project runs fine but when I open the project at work (ubuntu), the project fails to sync as the message says:
Gradle project sync failed. Basic functionality will not work properly.
Gradle DSL method not found: 'compile()'
Error:(11,0)
This is my module gradle
apply plugin: 'com.android.application'
apply plugin: 'com.parse'
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.parse.com/repo' }
}
dependencies {
classpath 'com.parse.tools:gradle:1.+'
compile 'com.stripe:stripe-android:+'
}
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.2.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
/* Uncomment if you enable ProGuard and you want to automatically upload symbols on build.
parse {
applicationId YOUR_APPLICATION_ID
masterKey YOUR_MASTER_KEY
// Make symbol upload automatic. Otherwise, use e.g. ../gradlew parseUploadSymbolsDebug;
uploadSymbols true
}
*/
and this is the project gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
ext {
compileSdkVersion = 22
buildToolsVersion = "22"
minSdkVersion = 9
targetSdkVersion = 22
}
Move compile 'com.stripe:stripe-android:+' from the dependencies closure in buildscript to your other dependencies closure. com.stripe:stripe-android is a library, not a Gradle plugin.
I want to use view pager indicator library in android studio. As it is available for the maven and not for the gradle project yet so I am adding library folder in android studio and including it in app build.gradle file. Problem arises, when I compiled the project so it wont compile as both the app and library gradle files are using android-support-v4.jar files. I need to know how can I use the library in android studio.
settings.gradle
include ':app'
include ':library'
include ':sample'
app/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
library.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
android {
sourceSets {
main {
java.srcDirs = ['src']
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
}
}
compileSdkVersion 19
buildToolsVersion '19.0.3'
}
dependencies {
compile files('libs/android-support-v4.jar')
// compile 'com.android.support:support-v4:19.+'
// compile fileTree(dir: 'libs', include: ['*.jar'])
}
Don't include the support library by adding a direct dependency to its jar file as you have in your library's build.gradle file. If you include it everywhere via the Maven-coordinate-style include, like your commented out line, the build system won't have trouble with duplicates:
dependencies {
compile 'com.android.support:support-v4:19.+'
}
Select "Projects" module in android studio.
download and unzip the ViewPagerIndicator-Library.
Create the libs folder under root folder and copy paste the library into that folder.
go to settings.gradle and add this line:
include ':libs:ViewPagerIndicator-Library'
add the compile project(':libs:ViewPagerIndicator-Library') in app's build.gradle model
Restart the studio and Have Fun ...
I have some problems with building multiproject with gradle. I read all similar questions but nothing help. The structure of my projects looks like:
App/
settings.gradle
app/
build.gradle
libraries/
Core(git submodule)/
Core/
build.gradle
libraries/
ZBarLibrary/
build.gradle
settings.gradle
App/settings.gradle
include ':App', ':libraries:Core', ':libraries:ZBarLibrary'
project(':libraries:Core').projectDir = new File(settingsDir, 'libraries/Core/Core')
project(':libraries:ZBarLibrary').projectDir = new File(settingsDir, 'libraries/Core/libraries/ZBarLibrary')
App/app/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile project(':libraries:Core')
}
App/libraries/Core/Core/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
instrumentTestCompile "junit:junit:4.5+"
compile project(':libraries:ZBarLibrary')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
App/libraries/Core/libraries/ZBarLibrary/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Command "gradle build" in App directory generates error: "package com… does not exist". This package is used in app module but it is find in App/libraries/Core/Core/src/main/java. Could you help me?
Your app module's build.gradle should contain (among other things)
apply plugin: 'com.android.application'
dependencies {
compile project(':my_library_module')
}
Your library module's build.gradle file should contain
apply plugin: 'com.android.library'
If you're using Core as library you should change apply plugin: 'android' to apply plugin: 'android-library' in App/libraries/Core/Core/build.gradle
To resolve the package not found errors, in the app module's build.gradle file I added
dependencies {
// ...
compile project(':library')
}
which adds the library module as a dependency to the app module
I have the same problem with Gradle 6.4 (multi-module project) and Java 13
Project structure:
app:
backend:
/src
build.gradle
base:
/src
build.gradle
build.gradle
settings.gradle
Main class is contained in base/build.gradle and also base-module depends on backend-module.
SOLUTION: It is necessary to add following rows to backend/build.gradle
jar {
enabled = true
}
bootJar {
enabled = false
}
and check that base/build.gradle has the following rows:
bootJar {
archivesBaseName = 'base'
}
dependencies {
implementation project(":backend")
}
Just in case, for newcomers in gradle put the listing of settings.gradle file:
rootProject.name = 'app'
include 'backend', 'base'