Deploy a Project in Eclipse with Gradle to a device - android

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
}

Related

Java, scala with gradle plugin in android studio

I saw the sample here to use scala with gradle plugin. I created a new android studio project. These are my gradle builds
Project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module app build.gradle
apply plugin: "com.android.application"
apply plugin: "jp.leafytree.android-scala"
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.ashwinxd.escalaandroidapp"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile "org.scala-lang:scala-library:2.11.7"
compile "org.scala-lang:scala-library:2.11.7"
compile "com.android.support:multidex:1.0.1"
compile "org.scalaz:scalaz-core_2.11:7.1.0"
}
The project compiles fine. There is no scala src directory generated. How do I proceed with using scala alongside java files? Is it necessary to use them in a source directory called scala? If so how do I generate it?
You have to create your own src/main/scala directory. That is where the scala gradle plugin looks for the scala source files. Just like the android plugin will look at src/main/java and src/androidTest/java.
That page describes you can customize that directory location at Put scala source files.

Add parse UI-widget but Gradle DSL Method not found: compile()

I'm trying to add the Parse UI widget by following the guide on https://github.com/ParsePlatform/ParseUI-Android. However, when I do that, I get an error that my project may be using a version of Gradle that does not contain the method and that the build file might be missing the Gradle plugin.
This is my Gradle module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.joakim.boken"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*jar')
}
// Module dependency on ParseUI libraries sources
compile project(':ParseUI-Widget')
// Uncomment if using Facebook Login (optional Maven dependency)
// compile 'com.facebook.android:facebook-android-sdk:4.0.1'
// compile files('YOUR_PROJECT_LIBS_PATH/ParseFacebookUtilsV4-1.10.0.jar')
and this 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Anybody know what I need to add or erase to get it working? I tried answers to similar questions, but so far nothing worked..
I'm not sure if it mattered that I downloaded the ZIP instead of cloning the repository?
You have to move this line inside the dependencies block:
compile project(':ParseUI-Widget')
It should be:
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*jar')
// Module dependency on ParseUI libraries sources
compile project(':ParseUI-Widget')
}

Android Studio 1.0.0 - Failed to find butterknife:6.0.0

I am using Android Studio 1.0.0. I am trying to add dependencies of butterknife.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.android.support:recyclerview-v7:21.0.2'
}
But i am getting the following Gradle error:
Error:Failed to find: com.jakewharton:butterknife:6.0.0
I had the same problem! Finally, when I tried to clean project I got more specific gradle error: No cached version of com.jakewharton:butterknife:6.0.0 available for offline mode. So the problem was that gradle offline mode was enabled! All you need to do is uncheck Settings -> Gradle -> Offline work ...
I added, below three lines, it got fixed. Thanks everyone.
repositories {
mavenCentral()
}
I tried in my build.gradle, it works.
In the root build.gradle. You can try put repositories { mavenCentral() } outside the buildscript, then it would work.
EDIT
build.gradle in app
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 21
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'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.jakewharton:butterknife:6.0.0'
}
build.gradle in root
// 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-rc4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
settings.gradle
include ':app'
Go to your project dir.
./gradlew clean
This downloaded the dependencies and resolved "Failed to find:" dependenices issue

View pager indicator in android studio

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 ...

Gradle is not automatically adding jar into project

Here is my build.gradle file
when I compile it always says 'cannot find symbol class HtmlFetcher' which is inside the de.jetwick.snacktory dependency
jar file of snacktory library is downloaded into local gradle cache
but it is not including it into project.
what might be a problem?
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {url "https://github.com/karussell/mvnrepo/raw/master/releases"}
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'de.jetwick:snacktory:1.1'
compile fileTree(dir: 'libs', include: '*.jar')
}
Upgrade to Android Studio 0.4.3. There are bugs with adding dependencies that have been fixed since 0.4.0.
compile fileTree(dir: 'libs', include: '*.jar')
That is the same line I use to compile my libs directory. I'm not sure if it's the version, as I've been using the above gradle line since 0.3 or so, and it's worked fine.
The only other thing to check would be the location of your libs folder.
Your libs folder needs to be inside of your Module.
Android studio projects are the same as IntelliJ projects meaning that the directory structure should be: ProjectName/ModuleName/libs
That means you need a libs directory on the same level as your src directory and build.gradle file. Double check it's in the right location.

Categories

Resources