Android-clean architecture sample program - android

I'm following an article from http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/ and downloaded the sample git hub project https://github.com/android10/Android-CleanArchitecture.
The project has been build using gradle, since my previous projects was build using the default builder of android, i found this hard building the project.
I already set up the environment of the gradle. but when I tried to build the project using gradle build on the root folder i get this error.(NOTE: Im using Intellij as my IDE)
I first performed gradle build in the root folder but received this error:
* Where:
Build file '/Users/magic/Desktop/android/myProjects/TestingProjects/Android Clean Architecture/Android-CleanArchitecture-master/data/build.gradle' line: 1
What went wrong:
A problem occurred evaluating project ':data'.
Failed to apply plugin [id 'android-library']
Gradle version 1.10 is required. Current version is 2.1. If using the gradle wrapper, try editing the distributionUrl in /Users/magic/Desktop/android/myProjects/TestingProjects/Android Clean Architecture/Android-CleanArchitecture-master/gradle/wrapper/gradle-wrapper.properties to gradle-1.10-all.zip
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
So, i went to folder gradle and change the gradle-wrapper.properties to gradle-1.10-all.zip and perfomed ./gradlew build but got this error:
FAILURE: Build failed with an exception.
Where:
Build file '/Users/Magic/Desktop/android/myProjects/TestingProjects/Android Clean Architecture/Android-CleanArchitecture-master/data/build.gradle' line: 9
What went wrong:
A problem occurred evaluating project ':data'.
Could not find method applicationId() for arguments [com.fernandocejas.android10.sample.data] on ProductFlavorDsl_Decorated{name=main, minSdkVersion=-1, targetSdkVersion=-1, renderscriptTargetApi=-1, renderscriptSupportMode=null, renderscriptNdkMode=null, versionCode=-1, versionName=null, packageName=null, testPackageName=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null}.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
and its pointing to line 9
defaultConfig {
applicationId "com.fernandocejas.android10.sample.data" //line 9
minSdkVersion 15
targetSdkVersion 19
}
I would really appreciate your inputs with this.
Thanks.

I just downloaded that project, imported it into Intellij 13.1 (using the gradle wrapper), and it worked out of the box. You have made changes to the build.gradle files that have broken it. It is hard to say what the issue is without all your gradle files posted here. One indication that the gradle files have been modified is that one of the errors you gave was:
Failed to apply plugin [id 'android-library']
But the example does not apply this plugin, it applies the correct one, i.e.:
apply plugin: 'com.android.library'
Try getting that project again and don't change the gradle build files. Also make sure you are importing with the gradle wrapper, and not your local distribution of gradle.
I hope this helps!

Related

Ionic Cordova Confused With The New Bundle Building For Android

I am tearing my hair out with the changes to how you submit an app to google. You now have to submit a bundle which i am trying to generate with ./gradlew bundle but i just keep getting confusing errors below:
* What went wrong:
A problem occurred evaluating project ':app'.
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
What went wrong:
A problem occurred configuring project ':app'.
compileSdkVersion is not specified. Please add it to build.gradle
The first issue is confusing because i have build tools installed, the path output is this:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:~/Library/Android/sdk/tools:~/Library/Android/sdk/platform-tools
Which is the correct location of the sdk.
The second error i don't follow at all, in my config.xml i have this:
I then ionic cordova build android --prod --release before the gradlew command is run. I also looked in the build.gradle file and found the following:
allprojects {
apply from: 'repositories.gradle'
repositories repos
//This replaces project.properties w.r.t. build settings
project.ext {
defaultCompileSdkVersion=29
defaultBuildToolsVersion="29.0.2" //String
defaultMinSdkVersion=22 //Integer - Minimum requirement is Android 5.1
defaultTargetSdkVersion=29 //Integer - We ALWAYS target the latest by default
defaultCompileSdkVersion=29 //Integer - We ALWAYS compile with the latest by default
}
}
So it's telling it to use compile sdk version 29 by default for all projects. If i add the following and then run gradlew:
android{
compileSdkVersion=29
}
I get the following issue when running gradlew:
Could not find method android() for arguments [build_86qvliu728ivbijvz823o6ru1$_run_closure2#2ba919e2] on root project 'android' of type org.gradle.api.Project.
I'm at a total loss!
Android SDK build tools are in the Android/sdk/build-tools.
So what I suggest first, please check if you've added ANDROID_SDK_ROOT in your environment variables. And it must refer to your Android SDK location (../Android/sdk)

install gradle wrapper when build failes because of wrong gradle version

I'm new to Gradle and Java development and I'm having a hard time using a Gradle project which requires an old version of Gradle.
Basically, the problem is that every gradle command I run ends up with the same error:
FAILURE: Build failed with an exception.
* Where:
Build file '/var/code/doron/reverb/libpulse-android/build.gradle' line: 10
* What went wrong:
A problem occurred evaluating project ':libpulse-android'.
> Failed to apply plugin [id 'android-library']
> Gradle version 1.10 is required. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in /var/code/doron/reverb/gradle/wrapper/gradle-wrapper.properties to gradle-1.10-all.zip
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s
From what I understood, the recommended way to work with this kind of project is to install and use the gradle wrapper - Use the ./gradlew command instead of the system's gradle. I have searched the internet and reached this web page: https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper Which basically says I should run:
gradle wrapper --gradle-version 1.10
But that ends in the same errors as above!
When searching for an answer, I have encountered this question: Getting error "Gradle version 1.10 is required. Current version is 1.12." when executing "gradle wrapper"? Which have failed to solve my problem. It seems the answers for that question only try to explain why the problem happens and not how to solve it.
Do you see why the problem is absurdly recursive? I can't install a needed version of Gradle in a wrapper because the build fails and the build fails because I don't use a specific version of gradle and I don't use the wrapper which I can't install.
If you don't yet have the Wrapper in your project: what you can do is to create a new temporary Gradle project, configure the wrapper in this project to match your needed gradle version, and then copy the wrapper related files into your initial project. If you already have a wrapper you can simply configure it by changing distribution url in ./gradle/wrapper/gradle.properties:
In details
1) create new empty project
mkdir tmp-project
cd tmp-project
gradle init
2) change wrapper version
gradle wrapper --gradle-version 1.10
3) check version (this will download the distribution)
$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-1.10-bin.zip
......................................
------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------
4) copy the wrapper related resources to your project:
./gradle/ directory
./gradlew script
./gradlew.bat script
open gradle-wrapper.properties in GradleScripts file change distributionUrl like below
#Thu Apr 12 11:14:54 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
don't forget to clean and rebuild project

Android Studio gives error: Gradle version 2.10 is required. Current version is 2.2.1 in Cordova project?

I have a Cordova/Phonegap application, every time when I rebuild the application using cordova build android it gives me below error.
ANDROID_HOME=/Users/name/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/name/Desktop/Ponet/zoomber/platforms/android/build.gradle' line: 22
* What went wrong:
A problem occurred evaluating root project 'android'.
> Failed to apply plugin [id 'android']
> Gradle version 2.10 is required. Current version is 2.2.1. If using the gradle wrapper, try editing the distributionUrl in /Users/name/Desktop/Ponet/zoomber/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.256 secs
Error: Error code 1 for command: /Users/name/Desktop/Ponet/zoomber/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/name/Desktop/Ponet/zoomber/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true
Recently I have updated my Android Studio 1.5 to 2.1 and imported previous project setting. Problem can be solved if I removed my android platform and add it again and rebuild the application. But this is very time consuming to do. Please provide any suggestions or solutions?
I tried below answers: (not Cordova specific)
Gradle version 2.10 is required. Current version is 2.8 Error
Thank you in-advance!
Edit the /Users/name/Desktop/Ponet/zoomber/gradle/wrapper/gradle-wrapper.properties file and set the distributionUrl property to
https\://services.gradle.org/distributions/gradle-2.14-all.zip
(current version at time of writing)

Gradle - A problems occurred evaluating root project '*'. > Could not find method compile() for arguments [*] on root project '*'

I'm using Eclipse Luna to develop my Android app. I don't have any idea why the error message keep showing again and again. I got this error message after fill up dependencies in build.gradle and run gradle build in my terminal.
build.gradle
dependencies {
compile 'com.lorentzos.swipecards:library:1.0.8#aar'
}
Error message
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/MNurdin/Documents/Github/Swipecards/example/src/main/build.gradle' line: 2
* What went wrong:
A problem occurred evaluating root project 'main'.
> Could not find method compile() for arguments [com.lorentzos.swipecards:library:X.X.X#aar] on root project 'main'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.34 secs
Project: https://github.com/datomnurdin/Swipecards
change to this:
compile 'com.lorentzos.swipecards:library:1.0.8'
I encountered the error when I tried using gradle 2.6 to build a project that was built using gradle 2.3. Make sure the versions are the same.
The compile task is defined by the java plugin. However, as you do not include it in your root project it does not exist there so gradle does not know how to handle it.
In order to resolve it you can either:
Apply the java plugin to your root project. The downside of this approach would be that this plugin will be included automatically in all your sub project that in somecases may be undesired, and also by default there will be an empty jar created for this project.
Define a dummy empty compile task yourself so gradle will be happy.
compile is a dependency configuration that comes from the Java Plugin.
The Android Gradle plugin applies the Java plugin under the covers. I do not see the Android plugin applied in your Gradle script. I think you may be missing a module-level build configuration that applies the Android Gradle plugin which would add dependencies.compile(...) to the DSL.

Android Studio 0.8 Task assemble not found in root project

I m trying to build the iosched app on ubuntu 14.04 on android studio 0.8 . After importing the setting.gradle file and following the build instruction I get an error saying
Error
:FAILURE: Build failed with an exception.
* What went wrong:
Task 'assemble' not found in root project 'iosched'.
* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
The solution mentioned in this post doesn't work either.
Try to add this: task assemble{} in your root build.gradle file.
According to this thread it helps (it helped me as well).
In my case, it was because my project implemented a Module that was an android-library (deprecated) / com.android.library which used a minSdkVersion lower than my project.
Be sure that your project and android-library / com.android.library have the same minSdkVersion.

Categories

Resources