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

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

Related

Could not resolve all files for configuration ':app:debugRuntimeClasspath gradle submodule dependency

I have a submodule project that turns into Maven repository, I'm trying to use a dependency implementation com.github.jkwiecien:EasyImage:3.0.3 other like Glide works, but this issue appears:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find com.github.jkwiecien:EasyImage:3.0.3.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/jkwiecien/EasyImage/3.0.3/EasyImage-3.0.3.pom
- https://jcenter.bintray.com/com/github/jkwiecien/EasyImage/3.0.3/EasyImage-3.0.3.pom
- https://maven.google.com/com/github/jkwiecien/EasyImage/3.0.3/EasyImage-3.0.3.pom
- https://repo.maven.apache.org/maven2/com/github/jkwiecien/EasyImage/3.0.3/EasyImage-3.0.3.pom
Required by:
project :app > project : myapp
I've tried putting maven repository as:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
def githubProperties = new Properties()
githubProperties.load(
new FileInputStream(rootProject.file("github.properties"))
)
def getVersionName = { ->
return "1.0.9"
}
def getArtifactId = { ->
return "rewards"
}
publishing {
publications {
rewards(MavenPublication) {
groupId 'app.my.sdk'
artifactId getArtifactId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtifactId()}-release.aar")
pom.withXml { // adding transitive dependencies...
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null ||
dep.name == null || dep.name == "unspecified")
return
final dependencyNode = dependenciesNode
.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)
if (!dep.transitive) {
final exclusionNode = dependencyNode
.appendNode('exclusions')
.appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
final exclusionNode = dependencyNode
.appendNode('exclusions')
.appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode(
'groupId', rule.group ?: '*')
exclusionNode.appendNode(
'artifactId', rule.module ?: '*')
}
}
} // end addDependency
configurations.compile.getDependencies().each { dep ->
addDependency(dep, "compile")
}
configurations.api.getDependencies().each { dep ->
addDependency(dep, "compile")
}
configurations.implementation.getDependencies().each { dep ->
addDependency(dep, "runtime")
}
} // end pomWithXml
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/my-project/my-lib")
credentials {
username = githubProperties['gpr.usr'] ?: System.getenv("GPR_USER")
password = githubProperties['gpr.key'] ?: System.getenv("GPR_API_KEY")
}
}
}
}
repositories {
maven {
URL "https://mvnrepository.com/artifact/com.github.jkwiecien/EasyImage"
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'jp.wasabeef:blurry:4.0.0'
implementation 'io.socket:socket.io-client:1.0.0'
implementation 'com.github.jkwiecien:EasyImage:3.0.3'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}
This is my full gradle file. I'm working only with this module, It's suppose to be an app inside another. I'm uploading in github packages using the maven.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
To solve this issue just add jitpack on gradle project file,
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

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.

Build failed for Error:Execution failed for task ':app:transformNative_libsWithMergeJniLibsForRelease'

I got this error when add project library gpuimage-library . to my app's gradle.build would fix the issue, however, it doesn't. Here is what my app's gradle.build currently looks like.
This is top-level build.gradle config:
// 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.2.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 app/build.gradle config:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'lib/armeabi-v7a/librsjni.so'
}
sourceSets.main.jni.srcDirs = []
sourceSets.main.jniLibs.srcDirs = ['src/main/libs', 'src/main/jniLibs']
task ndkBuild(type: Exec, description: 'Compile JNI source with NDK') {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir/ndk-build.cmd", '-C', file('src/main/jni').absolutePath
} else {
commandLine "$ndkDir/ndk-build", '-C', file('src/main/jni').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkClean(type: Exec, description: 'Clean NDK Binaries') {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "$ndkDir/ndk-build.cmd", 'clean', '-C', file('src/main/jni').absolutePath
} else {
commandLine "$ndkDir/ndk-build", 'clean', '-C', file('src/main/jni').absolutePath
}
}
clean.dependsOn 'ndkClean'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':stmobile')
compile project(':rajawali')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
testCompile 'junit:junit:4.12'
compile 'it.sephiroth.android.library.horizontallistview:hlistview:1.3.1'
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.android.support:cardview-v7:25.0.0'
compile 'com.facebook.android:audience-network-sdk:4.+'
compile project(':library')
}
Error:Execution failed for task ':app:transformNative_libsWithMergeJniLibsForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK lib/armeabi-v7a/libgpuimage-library.so
File1: C:\Users\DASF\Desktop\\ssss\app\build\intermediates\exploded-aar\jp.co.cyberagent.android.gpuimage\gpuimage-library\1.4.1\jni
File2: C:\Users\DASF\Desktop\ssssp\app\build\intermediates\exploded-aar\facesnap\library\unspecified\jni
What am I doing wrong and how to fix it ? . thank you support
Working solution for me is to add following in top-level build.gradle config:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}}

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

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.

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.

Categories

Resources