Android Studio update - Failed to resolve com.android.databinding - android

I recently updated my JAVA to 1.8 version and also made android studio updates and gradle plugin updates as well. After the update i get following error in one of my module's(i.e. facebook module) build.gradle file on compiling my project:
My project level build.gradle looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-beta4'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
}
allprojects {
repositories {
jcenter()
}
}
Also there are few Symbol not found error like Cannot resolve Symbol 'GradleScriptException' and Cannot resolve symbol 'MavenDeployment' in facebook module build.gradle file. The full code of facebook buil.gradle is:
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
project.group = 'com.facebook.android'
dependencies {
// Facbook Dependancies
testCompile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.parse.bolts:bolts-android:1.2.1'
// Unit Tests
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
def powerMockVersion = '1.6.1'
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion" testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
testCompile "org.powermock:powermock-api-mockito:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
// Connected Tests
androidTestCompile 'org.mockito:mockito-core:1.10.19'
}
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
multiDexEnabled true
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
dataBinding {
enabled = true
}
}
apply plugin: 'maven'
apply plugin: 'signing'
def isSnapshot = version.endsWith('-SNAPSHOT')
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
task setVersion {
// The version will be derived from source
project.version = null
def sdkVersionFile = file('src/main/java/com/facebook/FacebookSdkVersion.java')
sdkVersionFile.eachLine{
def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/)
if (matcher.matches()) {
project.version = matcher[0][1]
return
}
}
if (project.version.is('unspecified')) {
throw new GradleScriptException('Version could not be found.', null)
}
}
uploadArchives {
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'Facebook-Android-SDK'
artifactId = 'facebook-android-sdk'
packaging 'aar'
description 'Facebook Android SDK'
url 'https://github.com/facebook/facebook-android-sdk'
scm {
connection 'scm:git#github.com:facebook/facebook-android-sdk.git'
developerConnection 'scm:git#github.com:facebook/facebook-android-sdk.git'
url 'https://github.com/facebook/facebook-android-sdk'
}
licenses {
license {
name 'Facebook Platform License'
url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
distribution 'repo'
}
}
developers {
developer {
id 'facebook'
name 'Facebook'
}
}
}
}
}
uploadArchives.dependsOn(setVersion)
signing {
required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// JDK 1.8 is more strict then 1.7. Have JDK 1.8 behave like 1.7 for javadoc generation
if (org.gradle.internal.jvm.Jvm.current().getJavaVersion() == JavaVersion.VERSION_1_8) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
afterEvaluate {
androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
}
Clicking on Upgrade plugin and sync project does not do anything.
I have tried "Invalidate cache and restart" as suggested by various sources but it didn't work. I already have mentioned the latest version of gradle plugin in my project build.gradle.
I have gone through Gradle DSL Method not found: testCompile() but it does not resolve my issue.
What should i do to remove this compile error?
TIA
EDIT 1:
I made the change as suggested by sm4, And this DSL method not found error went off but now it fails to compile with the following error:

def powerMockVersion = '1.6.1'
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion" testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion" testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
testCompile "org.powermock:powermock-api-mockito:$powerMockVersion" androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
// Connected Tests
androidTestCompile 'org.mockito:mockito-core:1.10.19'
The testCompile is actually a call to a method. Because you have multiple testCompile on one line, it is being treated as a call to a method with many parameters. Such method does not exist.
Keep only one definition per line and it should work:
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion"
testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
testCompile "org.powermock:powermock-classloading-xstream:$powerMockVersion"
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
testCompile "org.powermock:powermock-api-mockito:$powerMockVersion"
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

After trying the fix mentioned by #sm4 i resolved the initial issue that i mentioned but it created another issue written in EDIT 1 section of question.
I followed this answer and then finally my project got compiled without any error.

Related

Android aar include jar dependency resources folder

Hello
While developing an Android AAR module, I encounter the following problem
My AAR module has a few jar dependencies, some of them have resources folder with error localized error messages. For some reason when I create the module AAR I noticed that Android build process exclude the resources folder from the jar dependency. The dependencies folder is an essential part since otherwise the error details are not found.
If something could shed light on the issue, I tried to create additional resources folder under main/resources//messages.properties but it didn't help.
Any help will be appreciated
here is my gradle file
apply plugin: 'com.android.library'
apply plugin: 'jacoco'
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
android {
compileSdkVersion 27
buildToolsVersion '26.0.3'
configurations {
javadocDeps
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled false
}
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
sourceSets {
androidTest {
...
}
test {
}
}
}
//assembleDebug.dependsOn(copyResDirectoryToClasses)
dependencies {
releaseCompile fileTree(include: ['*.jar'], dir: 'libs')
provided 'com.android.support:appcompat-v7:27.1.1'
provided 'org.jetbrains:annotations:16.0.3'
provided 'com.google.code.findbugs:annotations:3.0.1'
provided 'org.codehaus.sonar-plugins:sonar-ant-task:2.2'
provided 'org.jetbrains:annotations-java5:15.0'
provided 'com.google.android:annotations:4.1.1.4'
provided 'com.squareup.okhttp3:okhttp:3.9.1'
provided 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile files('../sdkSample/lib/qa_utils.jar')
androidTestCompile 'com.google.android:annotations:4.1.1.4'
javadocDeps 'com.android.support:appcompat-v7:27.1.1'
javadocDeps 'com.squareup.okhttp3:okhttp:3.9.1'
javadocDeps 'com.squareup.okhttp:okhttp-urlconnection:3.9.1'
javadocDeps 'com.google.code.findbugs:annotations:3.0.1'
javadocDeps group: 'org.mozilla', name: 'rhino', version: '1.7.7.1'
javadocDeps group: 'org.jetbrains', name: 'annotations', version: '16.0.3'
testCompile files('../sdkSample/lib/qa_utils.jar')
testCompile 'junit:junit:4.12'
testCompile 'org.json:json:20171018'
testCompile 'com.google.android:annotations:4.1.1.4'
testCompile 'org.testng:testng:6.13.1'
testCompile 'com.squareup.okhttp3:okhttp:3.9.1'
testCompile 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
testCompile 'org.robolectric:robolectric:3.8'
androidTestCompile 'com.squareup.okhttp3:okhttp:3.9.1'
androidTestCompile 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
}
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
if(it.project == 'sdkSample') {
it.onlyIf { false }
}
}
}
//ignore all test failures - is done temporary, the final solution is test categorization
project.gradle.taskGraph.whenReady {
-> project.tasks.findAll { it.name =~ /connected.+AndroidTest/ ||
it.name == "testDebugUnitTest" ||
it.name =="testReleaseUnitTest" }.each {
it.ignoreFailures = true
}
}
You need to use api instead of provided. You can find more info from here.
As i know aar cant have transitive dependencies. You may try export fat aar or you can give it a try to
implementation 'your.package:your_artifact:your_version' {transitive = true}
PS: Dont use type #aar
Also known as flatDir, because flatDir dependencies DOES NOT resolve transitives)
implementation 'your.package:your_artifact:your_version#aar' {transitive = true}
On the otherhand, you need to convert your project to maven standards. So that, you need a pom.xml file which points transitive dependencies under dependencies tag.
As you experienced jar files cant have resource files either. If you dont need to resource files, just export jar by executing createFullJarRelease task.
If you have to use .aar, you can add other dependencies that library uses in consumer.

Cannot create variant 'android-lint' after configuration

I am updating my project's Gradle plugin from 2.1.2 to 3.1.0 but the gradle starts throwing error while build :
Cannot create variant 'android-lint' after configuration
':app:debugRuntimeElements' has been resolved
project level gradle :
// Top-level build file
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'org.ajoberstar:gradle-git:0.6.3'
//noinspection GradleDynamicVersion
classpath 'io.fabric.tools:gradle:1.+'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'com.google.gms:google-services:3.0.0'
}
}
// Used to disable preDex, will speed up clean build but slow down incremental builds.
project.ext.preDexLibs = !project.hasProperty('disablePreDex')
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
}
allprojects {
repositories {
jcenter()
}
}
library level gradle :
apply plugin: 'com.android.library'
setVersion '1.2'
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
configurations {
classpaths
}
def sharedManifest = manifest {
attributes('Specification-Title': 'My App',
'Specification-Version': '2.1',
'Specification-Vendor': 'App Vendor',
'Implementation-Title': 'App',
'Implementation-Version': '2.1',
'Implementation-Vendor': 'App Vendor')
}
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
consumerProguardFile file("proguard-project.txt")
}
buildTypes {
debug {
testCoverageEnabled true
}
}
// work-around for duplicate files during packaging of APK
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(':exclude-doclet')
implementation 'com.android.support:support-annotations:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'commons-io:commons-io:2.4'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
implementation 'com.google.code.gson:gson:2.4'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.1.7'
classpaths files(new File(System.getenv("ANDROID_HOME") + "/platforms/android-${Integer.parseInt(rootProject.ANDROID_BUILD_SDK_VERSION)}/android.jar"),
new File(System.getenv("ANDROID_HOME") + "/extras/android/support/v4/android-support-v4.jar"))
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
}
android.libraryVariants.all { variant ->
String name = variant.buildType.name
task("generate${name.capitalize()}Javadoc", type: Javadoc) {
dependsOn variant.javaCompiler
description "Generates Javadoc for $project.name."
title "App $project.version"
source = variant.javaCompiler.source
classpath += project.files(variant.javaCompiler.classpath.files, android.getBootClasspath())
List<File> pathList = new ArrayList<File>()
pathList.add(new File(project(':exclude-doclet').libsDir,
"ExcludeDoclet-${project(':exclude-doclet').version}.jar"))
options {
doclet = "ExcludeDoclet"
docletpath = pathList
encoding = "UTF-8"
classpath = configurations.classpaths.files.asType(List)
linksOffline "http://developer.android.com/reference", "${android.sdkDirectory}/docs/reference"
links "http://docs.oracle.com/javase/7/docs/api/",
"http://square.github.io/retrofit/2.x/retrofit/",
"http://square.github.io/okhttp/2.x/okhttp/",
"http://reactivex.io/RxJava/javadoc/"
memberLevel = JavadocMemberLevel.PUBLIC
header = "AppKit"
}
exclude '**/BuildConfig.java'
exclude '**/R.java'
failOnError true
doLast {
copy {
from 'src/javadoc/assets/'
into destinationDir.path + '/assets/'
}
}
}
task("assemble${name.capitalize()}JavadocJar", type: Jar) {
dependsOn "generate${name.capitalize()}Javadoc"
description "Assembles Jar contaning Javadoc for $project.name."
from project.tasks.getByName("generate${name.capitalize()}Javadoc").destinationDir
classifier = 'javadoc'
manifest {
from sharedManifest
}
}
task("assemble${name.capitalize()}Jar", type: Jar) {
dependsOn variant.javaCompiler
description "Assembles Jar contaning $project.name."
from variant.javaCompiler.destinationDir
manifest {
from sharedManifest
}
}
artifacts {
archives project.tasks.getByName("assemble${name.capitalize()}Jar")
archives project.tasks.getByName("assemble${name.capitalize()}JavadocJar")
}
}
I am stuck with this issue and don't find any solution. Can anyone help me out.
I had the same issue with another library as you have.
I could resolve that with replacing this line:
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
with:
doFirst { classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) },
"This is due to new Gradle plugin when AndroidStudio gets updated that goes in conflict with JavaDoc plugin", If you have Javadoc task you must be able to find the same line.

Debug Mapbox Android NDK library

I am attempting to follow the Android Studio Experimental Plugin User Guide instructions located at:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental
to modify the Mapbox GL Native library located at:
https://github.com/mapbox/mapbox-gl-native
In specific, I have modified the following Android files:
https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/gradle/wrapper/gradle-wrapper.properties
https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/build.gradle
https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDK/build.gradle
https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
My goal is to modify the library so I can debug it. Ideally I would be able to use Android Studio to build the library and debug the C/C++ code. So far I can build it, but I can't debug it. A programmer working at Mapbox told me they don't how to debug the Android code either, so I suspect this isn't an easy goal to reach.
I have made many different attempts to apply the Android Studio Experimental Plugin User Guide instructions, but I'm not experienced at Gradle and my latest attempt is leaving me with the following error message which I don't understand:
Gradle 'android' project refresh failed
Error:Cause:org.gradle.api.internal.ExtensibleDynamicObject
Does anyone know how to modify these files to have them build a debuggable Android NDK Library? What is causing the above error?
I am using:
> Linux Mint 17.2
> Android Studio 2.1.1
> Build #AI-143.2821654, built on April 28, 2016
> JRE: 1.8.0_65-b17 amd64
> JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Below are the 4 files as I currently have them modified. Since I am new to Gradle, do not assume I have made any modfications correctly. I was merely attempting to apply the Android Studio Experimental Plugin User Guide instructions until I got a successful build.
Thanks
#// mapbox-gl-native/platform/android/gradle/wrapper/gradle-wrapper.properties
#Thu Apr 07 14:21:05 CDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#//distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
#//distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip
distributionSha256Sum=e77064981906cd0476ff1e0de3e6fef747bd18e140960f1915cca8ff6c33ab5c
// mapbox-gl-native/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
// classpath 'com.android.tools.build:gradle:2.1.0'
//classpath 'com.android.tools.build:gradle-experimental:0.7.0'
classpath 'com.android.tools.build:gradle-experimental:0.8.0-alpha2'
classpath 'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.12'
}
// mapbox-gl-native/platform/android/MapboxGLAndroidSDK/build.gradle
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.model.library'
apply plugin: 'checkstyle'
apply plugin: 'maven'
apply plugin: 'signing'
allprojects {
group project.GROUP
version project.VERSION_NAME
repositories {
mavenCentral()
}
}
repositories {
mavenCentral()
}
ext {
supportLibVersion = '23.4.0'
}
dependencies {
compile "com.android.support:support-annotations:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile 'com.squareup.okhttp3:okhttp:3.3.0'
compile 'com.mapzen.android:lost:1.1.0'
}
model {
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
sourceSets {
main.res.srcDirs += 'src/main/res-public'
}
repositories {
mavenCentral()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
lintOptions {
checkAllWarnings true
warningsAsErrors true
}
buildTypes {
debug {
jniDebuggable true
buildConfigField "String", "MAPBOX_EVENTS_USER_AGENT_BASE", new StringBuilder().append("\"").append("MapboxEventsAndroid/").append(project.VERSION_NAME).append("\"").toString()
}
release {
jniDebuggable false
buildConfigField "String", "MAPBOX_EVENTS_USER_AGENT_BASE", new StringBuilder().append("\"").append("MapboxEventsAndroid/").append(project.VERSION_NAME).append("\"").toString()
consumerProguardFiles 'proguard-rules.pro'
}
}
}
}
configurations {
all*.exclude group: 'commons-logging', module: 'commons-logging'
all*.exclude group: 'commons-collections', module: 'commons-collections'
}
model {
android.libraryVariants.all { variant ->
def name = variant.name
task "javadoc$name"(type: Javadoc) {
description = "Generates javadoc for build $name"
failOnError = false
destinationDir = new File(destinationDir, variant.baseName)
source = files(variant.javaCompile.source)
classpath = files(variant.javaCompile.classpath.files) + files(android.bootClasspath)
exclude '**/R.java', '**/BuildConfig.java', 'com/almeros/**'
options.windowTitle("Mapbox Android SDK $VERSION_NAME Reference")
options.docTitle("Mapbox Android SDK $VERSION_NAME")
options.header("Mapbox Android SDK $VERSION_NAME Reference")
options.bottom("© 2015–2016 Mapbox. All rights reserved.")
options.links("http://docs.oracle.com/javase/7/docs/api/")
options.linksOffline("http://d.android.com/reference/", "$System.env.ANDROID_HOME/docs/reference")
options.overview("src/main/java/overview.html")
options.group("Mapbox Android SDK", "com.mapbox.*")
options.group("Third Party Libraries", "com.almeros.*")
// TODO exclude generated R, BuildConfig, com.almeros.*
}
}
}
checkstyle {
configFile project.file('../checks.xml')
showViolations true
}
/*
task cleanJNIBuilds {
def jniLibsDir = new File("MapboxGLAndroidSDK/src/main/jniLibs")
delete jniLibsDir.absolutePath
}
*/
model
{
android.libraryVariants.all { variant ->
def name = variant.buildType.name
def checkstyle = project.tasks.create "checkstyle${name.capitalize()}", Checkstyle
checkstyle.dependsOn variant.javaCompile
checkstyle.source variant.javaCompile.source
checkstyle.classpath = project.fileTree(variant.javaCompile.destinationDir)
checkstyle.exclude('**/BuildConfig.java')
checkstyle.exclude('**/R.java')
checkstyle.exclude('**/com/almeros/android/multitouch/**')
project.tasks.getByName("check").dependsOn checkstyle
}
// From https://raw.github.com/mcxiaoke/gradle-mvn-push/master/jar.gradle
android.libraryVariants.all { variant ->
def jarTask = project.tasks.create(name: "jar${variant.name.capitalize()}", type: Jar) {
from variant.javaCompile.destinationDir
exclude "**/R.class"
exclude "**/BuildConfig.class"
}
jarTask.dependsOn variant.javaCompile
artifacts.add('archives', jarTask);
}
}
// From https://raw.github.com/mcxiaoke/gradle-mvn-push/master/gradle-mvn-push.gradle
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL :
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL :
"https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('USERNAME') ? USERNAME :
(hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "")
}
def getRepositoryPassword() {
return hasProperty('PASSWORD') ? PASSWORD :
(hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "")
}
task apklib(type: Zip) {
appendix = extension = 'apklib'
from 'AndroidManifest.xml'
into('res') {
from 'res'
}
into('src') {
from 'src'
}
}
artifacts {
archives apklib
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(),
password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(),
password: getRepositoryPassword())
}
/*
// Leaving out as artifact was incorrectly named when found
addFilter('aar') { artifact, file ->
artifact.name == archivesBaseName
}
addFilter('apklib') { artifact, file ->
artifact.name == archivesBaseName + '-apklib'
}
*/
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
model {
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.sourceFiles
classpath = files(android.bootClasspath)
}
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
model {
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
}
task makeClean(type: Exec) {
workingDir '../../'
commandLine 'make', 'clean'
}
task makeAndroid(type: Exec) {
workingDir '../../'
commandLine 'make', 'android'
}
task makeAndroidAll(type: Exec) {
workingDir '../../'
commandLine 'make', 'apackage'
}
// mapbox-gl-native/platform/android/MapboxGLAndroidSDKTestApp/build.gradle
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.model.application'
apply plugin: 'checkstyle'
task accessToken {
def tokenFile = new File("MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml")
if (!tokenFile.exists()) {
String tokenFileContents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<resources>\n" +
" <string name=\"mapbox_access_token\">" + "$System.env.MAPBOX_ACCESS_TOKEN" + "</string>\n" +
"</resources>"
if (tokenFileContents == null) {
throw new InvalidUserDataException("You must set the MAPBOX_ACCESS_TOKEN environment variable.")
}
tokenFile.write(tokenFileContents)
}
}
gradle.projectsEvaluated {
// preBuild.dependsOn('accessToken')
}
ext {
supportLibVersion = '23.4.0'
}
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.mapbox.mapboxsdk.testapp"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 9
versionName "4.1.0"
// Specify AndroidJUnitRunner as the default test instrumentation runner
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
lintOptions {
checkAllWarnings true
warningsAsErrors true
disable 'IconDensities'
disable 'InvalidPackage'
}
testOptions {
unitTests.returnDefaultValues = true
}
buildTypes {
debug {
// run code coverage reports
testCoverageEnabled = true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
}
dependencies {
compile(project(':MapboxGLAndroidSDK')) {
transitive = true
}
// Support libraries
compile "com.android.support:support-annotations:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
// Leak Canary
//debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
//releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
// Directions SDK
compile('com.mapbox.mapboxsdk:mapbox-android-directions:1.0.0#aar') {
transitive = true
}
// Geocoder SDK
compile('com.mapbox.mapboxsdk:mapbox-android-geocoder:1.0.0#aar') {
transitive = true
}
// Testing dependencies
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile "com.android.support:support-annotations:${supportLibVersion}"
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.4'
}
checkstyle {
configFile project.file('../checks.xml')
showViolations true
}
model {
android.applicationVariants.all { variant ->
def name = variant.buildType.name
def checkstyle = project.tasks.create "checkstyle${name.capitalize()}", Checkstyle
checkstyle.dependsOn variant.javaCompile
checkstyle.source variant.javaCompile.source
checkstyle.classpath = project.fileTree(variant.javaCompile.destinationDir)
checkstyle.exclude('**/BuildConfig.java')
checkstyle.exclude('**/R.java')
project.tasks.getByName("check").dependsOn checkstyle
}
}
Your gradle approach is essentially rewriting or porting the Android SDK Makefile to gradle. To solve what you are doing on Linux, you will likely need to modify the existing Makefiles.
The reason is that the Mapbox Android SDK build process uses make android to build the target libmapbox-gl.so. The Gradle project you have includes the .so file in with your usual Java code.
make android makes a call into mapbox-gl-native/Makefile
and also generates mapbox-gl-native/build/android-arm-v7/Makefile, which you may have to research how to modify to generate debug information as Chris Stratton mentions in the comments above.
When you do get around to modifying your C++, you will then need to modify the settings.gradle to make use of your modified .so for Android.
include ':MapboxGLAndroidSDK'
project(':MapboxGLAndroidSDK').projectDir = new File(rootProject.projectDir, '<relative-path-to>/../mapbox-gl-native/platform/android/MapboxGLAndroidSDK')
include ':app'
Another thing to consider — Can you build a debuggable version for Linux?
We have successfully debugged C++ for the Mapbox SDK using the Xcode debugger, as we built an iOS app as well. I know this will not fit your exact needs, but I mention it in case anyone else in your lab or organization has access to Xcode on OS X and can start debugging using make iproj.

Gradle DSL method not found: 'compile()' while using tesseract library

I have tried to import tesseract ocr project in android studio. While building gradle it showin error as following
Error:(8, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'textfairy' 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
My app/build.gradle file
import java.util.regex.Pattern
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
import org.apache.tools.ant.taskdefs.condition.Os
task ndkBuild(type: Exec,description: 'run ndk-build') {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
workingDir 'src/main/jni'
commandLine 'ndk-build.cmd', '-j', Runtime.runtime.availableProcessors()
} else {
workingDir 'src/main/jni'
commandLine "$ndkDir/ndk-build", '-j', Runtime.runtime.availableProcessors()
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(ndkBuild)
}
def getVersionCodeFromManifest(String prefix) {
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def version = prefix + matcher.group(1)
println sprintf("Returning version %s", version)
return Integer.parseInt("$version")
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
testInstrumentationRunner "android.test.InstrumentationTestRunner"
//testHandleProfiling true
//testFunctionalTest true
}
signingConfigs {
release
}
buildTypes {
debug {
debuggable true
}
release {
//runProguard true
proguardFile file('android.pro')
proguardFile getDefaultProguardFile('proguard-android.txt')
signingConfig signingConfigs.release
}
}
productFlavors {
x86 {
versionCode getVersionCodeFromManifest("6")
ndk {
abiFilter "x86"
}
}
aV7 {
versionCode getVersionCodeFromManifest("2")
ndk {
abiFilter "armeabi-v7a"
}
}
aV5 {
versionCode getVersionCodeFromManifest("1")
ndk {
abiFilter "armeabi"
}
}
}
sourceSets {
main {
//jniLibs.srcDirs = ['native-libs']
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build
}
}
}
def Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()) {
props.load(new FileInputStream(propFile))
if (props != null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
} else {
println 'signing.properties found but some entries are missing'
android.buildTypes.release.signingConfig = null
}
} else {
println 'signing.properties not found'
android.buildTypes.release.signingConfig = null
}
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
compile fileTree(dir: 'src/main/libs', include: '*.jar')
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.github.chrisbanes.photoview:library:1.2.2'
compile 'com.google.code.findbugs:jsr305:2.0.2'
compile "com.google.guava:guava:18.0"
compile 'de.greenrobot:eventbus:2.4.0'
//compile 'com.android.support:design:22.2.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:appcompat-v7:19.0.+'
compile 'org.apache.commons:commons-compress:1.5'
compile project(":tess-two:tess-two")
compile 'com.android.support:cardview-v7:21.0.+'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
androidTestCompile 'org.mockito:mockito-core:1.10.17'
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-all:1.10.19"
testCompile("org.robolectric:robolectric:3.0-rc2") {
exclude group: 'commons-logging', module: 'commons-logging'
}
compile('com.crashlytics.sdk.android:crashlytics:2.4.0#aar') {
transitive = true;
}
}
My project root build.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
}
allprojects {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "http://dl.bintray.com/populov/maven" }
jcenter()
maven {
url "http://oss.sonatype.org/content/repositories/snapshots"
}
}
}
dependencies {
apply plugin: 'osgi'
compile project(':libraries:tess-two')
}
My settings.gradle file
include ':libraries:tess-two'
include ':app'
My gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
I have added dependencies also. Please tell me what is the problem.
Thank you
You have to change your top-level build.gradle, removing the compile line, and adding the gradle and fabric plugin.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'io.fabric.tools:gradle:1.+'
}
}
allprojects {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "http://dl.bintray.com/populov/maven" }
jcenter()
maven {
url "http://oss.sonatype.org/content/repositories/snapshots"
}
}
}
Als if you want to use the libraries:tess-two in your project, you have to add this line inside the dependecies block of your app/build.gradle file
compile project(':libraries:tess-two')
Finally move the apply plugin: 'osgi' at the beginning of the app/build.gradle file
To resolve the ndk issue you have to:
add gradle.properties file to root folder of your project
add 'android.useDeprecatedNdk=true' to gradle.properties file
Here is my gradle.properties :
android.useDeprecatedNdk=true

Gradle generating incorrect POM subproject info

I have an Android project using Gradle 2.2, it has 2 sub projects and one is dependent on the other. I am using Maven plugin to deploy to Artifactory and it isn't generating the correct POM.
-project
-subproject1
-subproject2 (depends on subproject1)
subproject1/build.gradle, generates a JAR:
apply plugin: 'java'
apply plugin: 'maven'
def version = '1.0.0-SNAPSHOT'
def artifactId = 'subproject1'
def groupId = 'com.xxx.yyy'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'junit:junit:4.11'
compile 'org.slf4j:slf4j-api:1.7.7'
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'https://my-artifactory-repo' ) {
authentication(userName: ..., password: ...)
}
snapshotRepository(url: 'https://my-artifactory-repo' ) {
authentication(userName: ..., password: ...)
}
pom.version = version
pom.artifactId = artifactId
pom.groupId = groupId
}
}
}
task installArchives(type: Upload) {
configuration = configurations['archives']
repositories {
mavenDeployer {
repository url: 'my-local-repo-path'
pom.version = version
pom.artifactId = artifactId
pom.groupId = groupId
}
}
}
The subproject1 POM is generated correctly.
subproject2/build.gradle, generates an AAR:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.slf4j:slf4j-api:1.7.7'
compile project(':subproject1')
}
The subproject2 POM is not generated correctly, for subproject1, the groupid has the same value as artifactId and version is unspecified. Anyone know how to fix this?

Categories

Resources