Android: Cannot include https://github.com/wealdtech/hawk as a module - android

I am trying out Hawk authentication by https://github.com/wealdtech/hawk. I would like to include this library by source in an empty project so that I can experiment with the apis. I do not want to use a jar or gradle dependency.
I import the project as a module and I run into this error:
Error:(2, 0) Gradle DSL method not found: 'compile()'
Possible causes:<ul><li>The project 'HawkTest' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
I tried solutions from these links but I could not derive any information that could help resolve this issue:
Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.
Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.
I have spent many hours on this problem but do not seem anywhere near a solution. Any direction or a solution would be greatly appreciated.
This my top-level build file:
// 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
}
The app level file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.test.android.hawktest"
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.4.0'
}
The Hawk module's gradle file:
dependencies {
compile 'com.wealdtech:wealdtech-core:2.0.0'
compile 'com.wealdtech:wealdtech-configuration:2.0.0'
compile 'com.google.guava:guava:17.0'
}
uploadArchives {
repositories {
mavenDeployer {
pom.project {
pom.artifactId = 'hawk-core'
name 'Hawk Core'
description 'Java implementation of Hawk protocol - core'
}
}
}
}
And my directory structure:

hawk top level build.gradle contains all subproject configuration (check https://github.com/wealdtech/hawk/blob/develop/build.gradle)
For the whole process, from your project root directory :
git clone git#github.com:wealdtech/hawk.git
In your settings.gradle, this will configure the gradle modules :
include ':app',':hawk-core', ':hawk-server-jersey', ':hawk-client-jersey'
project(':hawk-core').projectDir = new File('hawk/hawk-core')
project(':hawk-server-jersey').projectDir = new File('hawk/hawk-server-jersey')
project(':hawk-client-jersey').projectDir = new File('hawk/hawk-client-jersey')
Then edit your top level build.gradle to specify the configuration for the Java project. Add the following :
configure(subprojects.findAll {it.name.startsWith('hawk')}) {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'signing'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
testCompile 'org.testng:testng:6.8'
}
task copyLibs (type: Copy) {
into "$buildDir/output/libs"
from configurations.testRuntime
}
task testJar (type: Jar) {
classifier = 'tests'
from sourceSets.test.output
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives jar
archives javadocJar
archives sourcesJar
}
}
You cant add Java plugin (apply plugin: 'java') for your Android project . If you do so, you will have this error : The 'java' plugin has been applied, but it is not compatible with the Android plugins.. This is why I use the configure(subprojects.findAll and perform a filter on hawk modules. I've copied the remaining configuration from https://github.com/wealdtech/hawk/blob/develop/build.gradle

Related

Android Studio project sync FAILED

I attempted to import a project that Udacity's android course provided, but there were some issues. In the build.grade(app module) I changed compile toimplementation and testCompile to testImplementation. The project synced successfully, but when I executed the project on the emulator it gave me the following errors.
Could not find com.android.tools.build:aapt2:3.3.1-5013011.
Searched in the following locations:
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- file:/C:/Users/root/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
- https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
- https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
Required by:
project :app
I think the required libraries needed to build cannot be found, but I don't know how to solve this. I googled the problem, but I can't find a solution.
My build.gradle file is this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
defaultConfig {
applicationId "com.example.android.miwok"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
api 'com.android.support:appcompat-v7:23.3.0'
api 'com.android.support:support-v4:23.3.0'
api 'com.android.support:design:23.3.0'
}
build.grade(project) is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// 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
}
Beginning with Android Studio 3.2, the source for AAPT2 (Android Asset Packaging Tool 2) is Google's Maven repository.
To use AAPT2, make sure that you have a google() dependency in your build.gradle file.
allprojects {
repositories {
google()
jcenter()
}
}
Check the official documentation.
The AAPT2 (Android Asset Packaging Tool) is a build tool that Android Studio and Android Gradle Plugin.
Android Gradle Plugin 3.0.0 and higher enable AAPT2 by default.
With Android Studio 3.2 to use AAPT2, make sure that you have a google() dependency in your build.gradle:
buildscript {
repositories {
google() // here
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
} allprojects {
repositories {
google() // and here
jcenter()
}

DSL method not found: implementation()

I tried to add the Fresco library by to my project by adding this to my app-level gradle file
implementation 'com.facebook.fresco:fresco:1.8.0'
Then I get the follwing error message:
Gradle DSL method not found: 'implementation()' Possible causes:
The project may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 3.0.1 and sync project
The project may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
The build file may be missing a Gradle plugin. Apply Gradle plugin
When I run gradle --version it tells me that I am using gradle 4.5.
This is my top-level gradle file.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "http://dl.bintray.com/populov/maven"}
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my app-level gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
defaultConfig {
applicationId "com.example.project1.3"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "state1.0"
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// lots of other dependencies
implementation 'com.facebook.fresco:fresco:1.8.0'
}
I also have this in my gradle-wrapper.properties file.
distributionUrl= https\://services.gradle.org/distributions/gradle-4.1-all.zip
I have basically tried everything from here https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html but the problem persists.
Any help would be greatly appreciated. Thank you!
My guess is that probably one of your other dependencies is causing the issue,
I run the exact same app & project gradle files you provided in a new project and synced with no problem.
You can try the following:
1) substitute implementation 'com.facebook.fresco:fresco:1.8.0' with compile'com.facebook.fresco:fresco:1.8.0' (deprecated but it will help with the troubleshooting) and see if it will sync properly.
2) start a new project and use the same gradle file and see if the problem still exists.
If nothing works please post the complete app level gradle file to check again.

Can't upload Android Kotlin Project to Fabric Beta with gradle

I created a project with Android Studio Preview 3.0 (Canary 2) to start Kotlin development. I used the Android Studio Fabric Plugin to setup Fabric for my project.
But when I want to upload a beta version of my app to Fabric Beta (Crashlytics) with the following command
./gradlew crashlyticsUploadDistributionDebug
I receive the following error:
Configuration 'compile' in project ':app' is deprecated. Use
'implementation' instead. Configuration 'testCompile' in project
':app' is deprecated. Use 'testImplementation' instead. The
Task.leftShift(Closure) method has been deprecated and is scheduled to
be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
registerResGeneratingTask is deprecated, use
registerGeneratedFolders(FileCollection) registerResGeneratingTask is
deprecated, use registerGeneratedFolders(FileCollection)
:app:crashlyticsUploadDistributionDebug FAILED
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:crashlyticsUploadDistributionDebug'.
Not valid.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED in 1s 1 actionable task: 1 executed, 0 avoided (0%)
I do not have any idea, what "Not valid" means.
This is my root build.gradle:
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
maven { url 'https://maven.google.com' }
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.ajoberstar:grgit:1.9.0'
classpath 'io.fabric.tools:gradle:1.22.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
supportLibVersion = "25.3.1"
buildVersion = "25.0.3"
daggerVersion = "2.9"
rxJavaVersion = "2.1.0"
rxAndroidVersion = "2.0.1"
countGitCommits = { ->
git = Grgit.open()
def commitCount = git.log(includes: ['HEAD']).size()
println("INFO: Number of commits $commitCount")
return commitCount
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the app build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 25
buildToolsVersion "$buildVersion"
defaultConfig {
applicationId "com.kotlin.sample"
minSdkVersion 21
targetSdkVersion 25
def numberOfCommits = countGitCommits()
versionCode 1000 + numberOfCommits
versionName "0.1.$numberOfCommits"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile files('libs/API_ADK.jar')
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:support-v4:$supportLibVersion"
compile "com.android.support:design:$supportLibVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'io.reactivex.rxjava2:rxkotlin:2.0.3'
compile "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
compile "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
compile 'com.jakewharton.timber:timber:4.5.1'
compile "com.google.dagger:dagger:$daggerVersion"
// Needed for #Generated annotation (missing in Java <= 1.6; therefore, Android)
compile 'javax.annotation:jsr250-api:1.0'
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
testCompile 'junit:junit:4.12'
}
The fabric.properties file with the apiSecret is also placed in the project.
Edit:
A manual upload of the APK to Fabric Beta works.
I just want to point to the comment from Mike Bonnell as it answers this question:
Our command line tools are not compatible with the Alpha version of Gradle 3. We're looking into the changes that have come with the alpha versions, but we test against betas and stable versions of the releases.
Edit 2017/08/25
Tried with Android Studio 3.0 Beta 3 and the corresponding android gradle plugin. The gradle task crashlyticsUploadDistributionDebug seems to work again.

android : cannot build project after upgrading Android Studio to 2.3

So, happily updated my Android Studio from stable version 2.2 to canary channel 2.3.
But, unfortunately, it has serious bug. Project is not able to build.
I tried opening my previous projects and also tried creating new sample application, I got same below error:
Gradle 'MyApplication' project refresh failed
Error:A problem occurred configuring project ':app'.
build.gradle(project):
// 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.3.0-alpha1'
// 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
}
build.gradle(app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.chint.myapplication"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:25.0.0'
testCompile 'junit:junit:4.12'
}
Am I the only one with this issue ?
So, be careful while this dialog appears:
Choose "Remind me later" and NOT "Update"
Stay with the build version you already have.
Incase, you pressed Update, so just rollback your Android Gradle Plugin classpath in build.gradle(project) to below one:
classpath 'com.android.tools.build:gradle:2.2.2'
This worked for me.
You should update your Android Studio gradle manually.
1° Step:
Follow this path and get your gradle version
C:\Users\[USER_NAME]\.gradle\wrapper\dists
Here you will get "gradle-X.X" (X- is version) in my case it was "gradle-3.3-all"
2° Step:
Go to the following link :
https://services.gradle.org/distributions/
Download your respective version zip file and just past it in the last folder with long random name.
C:\Users\[USER_NAME]\.gradle\wrapper\dists\gradle-x.x\55gk2rcmfc6p2dg9u9ohc31212 HERE
Now open the Android studio, I hope this will work.
I fought a similar issue and resolved it with the addition of 2 characters...
And after updating the gradle-wrapper.properties to target 3.2.1 everything was great for me
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-all.zip
If you import external libraries apply changes for "allprojects"
// 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.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Failed to resolve JitPack Android library

I host my library with Github repo and created a release with JitPack. Now when I want to get it with Android Studio, I get this error message:
Failed to resolve: com.github.AhmedCommando:emojis_managers:v1.1
This is my build Gradle:
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.AhmedCommando'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard->android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
// build a jar with source files
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
// build a jar with javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
This is how I app build Gradle:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
Thank you for your help.
Try this:----
Step 1. Add the JitPack maven repository to the list of repositories:
url "https://jitpack.io"
Step 2. Add the dependency information:
Group: com.github.Username
Artifact: Repository Name
Version: Release tag, commit hash or -SNAPSHOT
That's it! The first time you request a project JitPack checks out the code, builds it and sends the Jar files back to you.
To see an example head to jitpack.io and 'Look Up' a GitHub repository by url.
Gradle example:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.User:Repo:Version'
}
Note: when using multiple repositories in build.gradle it is recommended to add JitPack at the end. Gradle will go through all repositories in order until it finds a dependency.
Snapshots
Snapshot versions are useful during development. A snapshot is a version that has not been released. The difference between a real version and a snapshot is that snapshot might still get updates. Snapshot versions are useful during development process and JitPack provides two ways to get them. You can specify a version for your dependency as:
commit hash
branch-SNAPSHOT (replace 'branch' with any branch name, e.g. master)
For example:
// dependency on the latest commit in the master branch
compile 'com.github.jitpack:gradle-simple:master-SNAPSHOT'
have you added the compile portion to the gradle?
dependencies {
compile 'com.github.AhmedCommando:emojis_managers:v1.1'
}
I do not see that in the gradle that you have posted

Categories

Resources