Java, scala with gradle plugin in android studio - android

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.

Related

How to add TIKA into build.gradle using android studio?

I'm trying to put Apache Tika into my project.
But it returns error, unfortunately, I couldn't solve this problem by myself.
How can I put Apache Tika using android studio?
Error:(27, 0) Gradle DSL method not found: 'runtime()'
Possible causes:The project 'AudioTest' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.test.audiotest"
minSdkVersion 16
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
runtime 'org.apache.tika:tika-parsers:1.13'
}
this is my build.gradle module:app
// 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.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
this is my build.gradle project:AudioTest
change
runtime 'org.apache.tika:tika-parsers:1.13'
to
compile 'org.apache.tika:tika-parsers:1.13'

Gradle build failed for two dependencies

I am trying to build gradle with the following dependencies. but its not compiling. I have tried a lot by changing the versions by seeing forums. I search for the dependencies in project structure dialog and found the following two.
de.hdodenhof:circleimageview:2.0.0
com.mcxiaoke.volley:library-aar:1.0.1
Actually I am using two pc. This was build in another pc with following
de.hdodenhof:circleimageview:1.2.1
com.mcxiaoke.volley:library-aar:1.0.19
Still no luck and the gradle build taking 20-25 minutes each time
Main 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.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.map"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4#aar') {
transitive = true
}
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:recyclerview-v7:23.0'
}
This sounds like gradle is unable to reach the remote repository. Does your firewall block it, is your internet connection working,...?

Adding Dagger-2 to Android Studio

I asked this question previously https://stackoverflow.com/questions/35981039/instrumentation-doesnt-inject-touch-in-rooted-device which states that instrumentation doesn't work on Lollipop and later versions. After some deep search I found that we should add Dagger-2 to be compiled with the project. I used the steps related to gradle available here: https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2
This is my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
This is app/build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.project.android.vecsat"
minSdkVersion 10
targetSdkVersion 19
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:19.0.0'
compile 'com.android.support:support-v4:19.0.0'
apt 'com.google.dagger:dagger-compiler:2.0.2'
compile 'com.google.dagger:dagger:2.0.2'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile project(':libraries:opencv')
}
After synchronizing the project, nothing was fixed. Still instrumentation doesn't work. I found another guide here: https://github.com/kkovach/dagger/blob/update-install-gradle/README.md
But, I don't know where to place dagger jar file, and I can't figure out where is java gradle.
Can somebody please help me? What are the correct steps to add Dagger-2 to the project?

Android Studio Gradle DSL method not found: 'mavencentral()'

I am trying to use facebook SDK in my android apps, and I am starting to add maven central repository to my build.gardle. Although, I've found 2 build.gardle which belong to project and app. Here they are;
Android Studio: 1.5.1
Gradle Version: 2.8
Android Plugin Version: 1.5.0
Build.gardle (Project)
buildscript {
repositories {
jcenter()
mavencentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
}
}
allprojects {
repositories {
jcenter()
mavencentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build.gardle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.test"
minSdkVersion 15
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
}
Yet I get this following error during build;
Gradle DSL method not found: mavencentral()
I have tried;
Checking both gardle files
Removing android compile dependencies that's actually should be there
Checking android packagingOptions.exclude
Checking if there's android method in the gardle
And, I haven't tried to update my gardle or android studio, but I am just wondering whether it's really needed or I am doing something wrong with my build.gardle.
Any suggestion is appreciated. Thank you.
The Facebook SDK page is clear. Add into your project/build.gradle
repositories {
mavenCentral() //note the uppercase C
}
and into your project/app/build.gradle
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.+'
}

Android aar dependencies

I am new to Gradle build system, I have a library project which includes dependencies like Retrofit, okhttp etc.
I compiled my project and created an aar file. I created a dummy project and added my library aar as a dependency.
Now if I don't add Retrofit and okhttp as dependency in my dummy app's build.gradle file, my app crashes with class not found exception.
My Question is : Since the library aar file already includes Retrofit and okhttp as dependency then why do I need to add them explicitly in dummy app's build.gradle file too? Is there a workaround.
Here is my library build.gradle
apply plugin: 'com.android.library'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
}
}
allprojects {
repositories {
jcenter()
}
}
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
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.+'
compile 'com.android.support:recyclerview-v7:21.+'
compile 'com.android.support:cardview-v7:21.+'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
I was able to resolve this by adding the aar file to a local maven repository. Somehow just adding aar in libs folder and including it as a dependency does not fixes the problem.
If you encounter similar problem just modify your library project build.gradle with these additions
apply plugin: 'maven'
version = "1.0"
group = "com.example.lib"
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.github.dcendents:android-maven-plugin:1.0'
}
}
repositories {
mavenLocal()
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
Run the task in the terminal provided in the Android studio itself as ./gradlew uploadArchives
Then in your app module's build.gradle file, add the library as dependency
compile ('com.example.app:ExampleLibrary:1.0#aar') {
transitive = true;
}

Categories

Resources