I created a project and I added the following to my build.gradle file, about which I got this error message A problem occurred evaluating root project NewsFeeder. Plugin with id android not found
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Is this your complete build.gradle ?
If so, you are missing
apply plugin: 'android'
usually above repositories block.
Also I think you need buildscript block to identify which gradle to be used.
Example build.gradle looks like
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
maven {
url 'https://github.com/Goddchen/mvn-repo/raw/master/'
}
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v13:13.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
..... other configs .....
}
Related
In one of my projects I need to use GoogleMaps and Firebase for notifications but the libraries of the service and the Firebase in place do not want to work.
buildscript {
repositories {
google()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.google.android.gms:play-services:8.4.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
jcenter()
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://maven.google.com" }
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.online.app"
minSdkVersion 16
targetSdkVersion 25
versionCode 8
versionName "2.5"
multiDexEnabled true
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:26.0.2'
compile 'me.leolin:ShortcutBadger:1.1.6#aar'
compile('com.crashlytics.sdk.android:crashlytics:2.6.0#aar') {
transitive = true;
}
compile "com.google.firebase:firebase-ads:11.8.0"
compile "com.android.support:appcompat-v7:26.1.0"
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.android.gms:play-services'
Error:
Gradle sync failed: Plugin with id 'com.google.android.gms:play-services' not found.
Consult IDE log for more details (Help | Show Log) (2s 325ms)
change this:
apply plugin: 'com.google.android.gms:play-services'
to this:
apply plugin: 'com.google.gms.google-services'
check this for more info: https://developers.google.com/android/guides/google-services-plugin
You need to use
apply plugin: 'com.google.gms.google-services'
You have 2 errors:
In your buildscript block use the right plugin:
dependencies {
classpath 'com.google.gms:google-services:3.1.1'
// ...
}
Instead of classpath 'com.google.android.gms:play-services:8.4.0'
Then at the bottom you have also to change the name of the plugin:
apply plugin: 'com.google.gms.google-services'
instead of:
apply plugin: 'com.google.android.gms:play-services'
Also don't use 2 buildscript blocks.
Just remove this block, and add the repository and the plugin in the previous block:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
I am trying to build a basic app using Kotlin/Anko but I am getting the following duplicate file exception
Execution failed for task
':app:transformResourcesWithMergeJavaResForDebug'.>
com.android.build.api.transform.TransformException:
com.android.builder.packaging.DuplicateFileException: Duplicate files
copied in APK kotlin/internal/internal.kotlin_builtins File1:
C:\Users\mahesh.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-runtime\1.0.6.\3562c66f648480d3bd4f76cff722488ced13445b\kotlin-runtime-1.0.6.jar File2:
C:\Users\mahesh.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.0.6\4008eb91a337b377dae7e4572b8b543e5321f549\kotlin-compiler-embeddable-1.0.6.jar
Following is the code for the app level gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kotlin.androdikotlinexample"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
//kotlin
compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
//anko
compile "org.jetbrains.anko:anko-design:0.8.3"
compile "org.jetbrains.anko:anko-support-v4:0.8.3"
compile "org.jetbrains.anko:anko-sdk15:0.8.3"
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.3'
}
Following is the code for Project level gradle file:
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
And this is the basic code for the MainUI file
class MainUI : AnkoComponent<MainActivityKotlin> {
override fun createView(ui: AnkoContext<MainActivityKotlin>): View = with(ui) {
coordinatorLayout {
verticalLayout {
// maybe put some content here
}
floatingActionButton {
imageResource = android.R.drawable.ic_menu_edit
onClick {
ui.owner.startActivityForResult<MainActivityKotlin>(1)
}
}.lparams {
gravity = Gravity.BOTTOM or Gravity.END
}
}
}
}
And the content is set on MainActivityKotlin file using the method MainUI().setContentView(this) in its onCreatemethod.
I have tried deleting the gradle cache and building the project again but nothing works. Please let me know where am I going wrong?
Remove compile "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" from your gradle
Remove also all buildscript section from you app level gradle
Try this one:
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile ("org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version") {
transitive = false
}
Also you don't need the android-extensions dependency anymore, as it's bundled into the plugin. Just having the apply plugin: 'kotlin-android-extensions' in your gradle is enough.
For historical reason instrumentation tests are not stored in androidTests directory as required and i can't change directories structure (actually whole app is tests for the library used). I was able to build and install apk with gradle, but no tests were found:
:app-tests:connectedDebugAndroidTest
Tests on test_avd(AVD) - 4.1.2 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
com.android.builder.testing.ConnectedDevice > No tests found.[test_avd(AVD) - 4.1.2] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack #Test annotations).
:app-tests:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app-tests:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/asmirnov/Documents/dev/src/project/app-tests/build/reports/androidTests/connected/index.html
Actually the tests are in src folder, written correctly and can be built/runned using Ant:
public abstract class BaseTest extends AndroidTestCase
{
...
public class AppInfoTest extends BaseTest
{
#Test
public void testAllProperties()
{
...
...
How can i make Gradle process src folder as android (instrumentation) tests?
Here is my current build.gradle file (it uses the experimental Android Gradle plugin version 0.7.2 because we have an NDK library):
apply plugin: 'com.android.model.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
model {
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sources {
main {
// overriding paths from default ones to actual ones
// what about 'androidTests' ?
manifest { source {
srcDir '.'
include 'AndroidManifest.xml'
} }
java { source { srcDirs = ['src'] } }
res { source { srcDirs = ['res'] } }
jni {
dependencies {
project ":library" // native library dependency
}
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
}
UPDATE 1 (for sschuberth):
Config:
apply plugin: 'com.android.model.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
model {
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion.apiLevel 9
targetSdkVersion.apiLevel 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
androidTest {
manifest.srcFile 'AndroidManifest.xml' // error here
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library')
}
Error
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/asmirnov/Documents/dev/src/project/app-tests/build.gradle' line: 32
* What went wrong:
A problem occurred configuring project ':app-tests'.
> Exception thrown while executing model rule: android { ... } # app-tests/build.gradle line 16, column 5
> Could not find property 'manifest' on source set 'android test'.
Not completely sure this will work for your scenario, but you can update the root of the androidTest sourceSet like this
android {
sourceSets {
androidTest.setRoot('src')
}
}
There is also a test source set if it's just Java code, nothing Android specific.
You could also play around with the java.srcDir setting...
The above setting will look at these locations for your files.
<project>/<module>/src/AndroidManifest.xml
<project>/<module>/src/java
If you'd like to move both into the /src directory, you can use
sourceSets {
androidTest {
setRoot 'src'
java.srcDirs = ['src']
}
}
More Android Gradle details can be read at Configuring the Structure
You are welcome to debug these settings yourself with this setup
sourceSets {
androidTest {
setRoot 'src'
java.srcDirs = ['./src']
}
println "androidTest.manifest.srcFile = ${androidTest.manifest.srcFile}"
println "androidTest.java.srcDirs = ${androidTest.java.srcDirs}"
}
When you just clean the project, you'll see those lines being printed to the console
Instead of sources {} you should use sourceSets {} and the androidTest source set to customize the test source code location:
model { // Required for experimental plugin.
android {
sourceSets {
androidTest {
manifest.srcFile '../AppTest/AndroidManifest.xml'
java.srcDirs = ['../AppTest/src']
res.srcDirs = ['../AppTest/res']
assets.srcDirs = ['../AppTest/assets']
}
}
}
}
Note that this not not apply to unit test. For unit test (like with Robolectric), use the test source set.
It was tricky solution: to use experimental gradle plugin to compile native code with NDK and regular gradle plugin for test app.
build.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
// experimental gradle plugin for the library to compile native code with NDK
classpath "com.android.tools.build:gradle-experimental:0.7.2"
// regular gradle plugin for the tests
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
subprojects {
task listAllDependencies(type: DependencyReportTask) {}
}
library gradle (experimental):
apply plugin: 'com.android.model.library'
...
model {
android {
...
ndk {
moduleName = "library-jni"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
stl = "c++_static"
abiFilters.addAll(['armeabi-v7a', 'x86']) // supported abis only
}
...
}
...
}
app/build.gradle (regular):
apply plugin: 'com.android.application'
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.tests"
minSdkVersion 9
targetSdkVersion 16
versionCode 359
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
androidTest {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
jni {
dependencies {
project ":library"
}
}
}
}
}
dependencies {
androidTestCompile project(':library')
androidTestCompile fileTree(include: ['*.jar'], dir: 'libs')
}
I have some build.gradle file this
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
that throws this error :
A problem occurred configuring root project 'NewsFeeder'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not find any version that matches com.github.chrisbanes.actionbarpulltorefresh:library:+.
Required by:
:NewsFeeder:unspecified
But, this reference to chrisbanes's actionbarpulltorefresh seems to be correct : https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/QuickStart-Stock. How can it be since in this project is available in [maven central repo][1] ?
For information, I set in some local.propertiesfile sdk.dir=/home/adt-bundle-mac-x86_64-20130522/sdk, which is the same that what echo $ANDROID_SDK returns
You need to tell gradle where it can look to find the dependency. If you want gradle to use the mavenCentral repository then add this to your build.gradle file:
repositories {
mavenCentral()
}
The buildscript repositories is just for the build script dependencies, not project dependencies. You want to add the repositories entry at the outer most, or project, level.
Your build.gradle would look like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
android {
compileSdkVersion 18
buildToolsVersion '18'
defaultConfig {
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
I receive this error :
Gradle: Execution failed for task ':Foo:dexDebug'.
And since 2day ! I have try a lot of solution... But nothing work fine ! Really ! Need Help !
I work with android Studio. (IntelliJ IDEA)
For this following three directory
FooProject [RootProject]
|-gradle
|-libraries
|-facebook [library1]
|-libs
|-android-support-v4.jar
|-res
|-*.(drawable...)
|-src
|-*.java
|-build.gradle
|-AnroidManifest.xml
|-facebook.iml
|-foosdk [library2]
|-res
|-*.(drawable...)
|-src
|-*.java
|-libs
|-YouTubeAndroidPlayerApi.jar
|-build.gradle
|-AnroidManifest.xml
|-foosdk.iml
|-Foo [project for execution]
|-libs
|-commons-io-1.3.2.jar
|-commons-lang3-3.1.jar
|-jackson-core-asl-1.9.11.jar
|-jackson-databind-2.1.4.jar
|-jackson-mapper-asl-1.9.11.jar
|-robospice-1.4.1-SNAPSHOT.jar
|-robospice-cache-1.4.1-SNAPSHOT.jar
|-robospice-spring-android-1.4.1-SNAPSHOT.jar
|-spring-android-core-1.0.1.RELEASE.jar
|-spring-android-rest-template-1.0.1.RELEASE.jar
|-YouTubeAndroidPlayerApi.jar
|-src
|-main
|-java
|-*.java
|-res
|-*.(drawable...)
|-build.gradle
|-AnroidManifest.xml
|-Foo.iml
|-gradlew
|-gradlew.bat
|-local.properties
|-settings.gradle
|-RootProject.iml
I have for my settings.gradle
include ':libraries:facebook', :libraries:foosdk', ':foo'
For the files "build.gradle" :
For libraries/facebook/build.gradle
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
For libraries/foosdk/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
For Foo/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile project(':libraries:foosdk')
compile project(':libraries:facebook')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src']
res.srcDirs = ['src/main/res']
}
}
}
Is your Foo project in /Foo or /foo folder (note the upper case)? You may need to correct the include 'foo' to 'Foo'?
If that doesn't work, please paste the info or debug output of your Gradle build. If you're running AndroidStudio and don't have any output, go to the root of your project and run gradlew.bat assembleDebug --info (on Wins) or ./gradlew assembleDebug --info (on Linux/Mac) or --debug and paste the output here so we can see what went wrong exactly.