From 0803cef3b9c54002ecfea1d87fdb0559dbe8b7ef Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Fri, 24 May 2013 10:02:38 -0700 Subject: Fix dependencies management. Instead of manually combining the different Configuration objects (defaultConfig, build Type, flavor(s)), we know create composite Configurations objects for each variant that will extends all those previous Configurations. This allows Gradle to resolve the dependencies at the variant level, detecting conflict, selecting version based on all the dependencies instead of just the one from a given Configuration. This also allows the test variant of a library project to properly include the dependencies of the library itself. Change-Id: I5bbc0db7dc97fd794c546091ff7eaeb3a51d7eb2 --- tests/libTestDep/build.gradle | 23 ++++++++ .../android/tests/libdeps/MainActivityTest.java | 61 +++++++++++++++++++++ tests/libTestDep/src/main/AndroidManifest.xml | 21 +++++++ .../com/android/tests/libdeps/MainActivity.java | 15 +++++ .../src/main/res/drawable-hdpi/ic_launcher.png | Bin 0 -> 4147 bytes .../src/main/res/drawable-ldpi/ic_launcher.png | Bin 0 -> 1723 bytes .../src/main/res/drawable-mdpi/ic_launcher.png | Bin 0 -> 2574 bytes tests/libTestDep/src/main/res/layout/lib1_main.xml | 13 +++++ tests/libTestDep/src/main/res/values/strings.xml | 7 +++ 9 files changed, 140 insertions(+) create mode 100644 tests/libTestDep/build.gradle create mode 100644 tests/libTestDep/src/instrumentTest/java/com/android/tests/libdeps/MainActivityTest.java create mode 100644 tests/libTestDep/src/main/AndroidManifest.xml create mode 100644 tests/libTestDep/src/main/java/com/android/tests/libdeps/MainActivity.java create mode 100644 tests/libTestDep/src/main/res/drawable-hdpi/ic_launcher.png create mode 100644 tests/libTestDep/src/main/res/drawable-ldpi/ic_launcher.png create mode 100644 tests/libTestDep/src/main/res/drawable-mdpi/ic_launcher.png create mode 100644 tests/libTestDep/src/main/res/layout/lib1_main.xml create mode 100644 tests/libTestDep/src/main/res/values/strings.xml (limited to 'tests/libTestDep') diff --git a/tests/libTestDep/build.gradle b/tests/libTestDep/build.gradle new file mode 100644 index 0000000..001edb0 --- /dev/null +++ b/tests/libTestDep/build.gradle @@ -0,0 +1,23 @@ +buildscript { + repositories { + maven { url '../../../../out/host/gradle/repo' } + } + dependencies { + classpath 'com.android.tools.build:gradle:0.5.0-SNAPSHOT' + } +} + +apply plugin: 'android-library' + +repositories { + mavenCentral() +} + +dependencies { + compile 'com.google.guava:guava:11.0.2' +} + +android { + compileSdkVersion 15 + buildToolsVersion "17.0" +} \ No newline at end of file diff --git a/tests/libTestDep/src/instrumentTest/java/com/android/tests/libdeps/MainActivityTest.java b/tests/libTestDep/src/instrumentTest/java/com/android/tests/libdeps/MainActivityTest.java new file mode 100644 index 0000000..23c8303 --- /dev/null +++ b/tests/libTestDep/src/instrumentTest/java/com/android/tests/libdeps/MainActivityTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.tests.libdeps; + +import android.test.ActivityInstrumentationTestCase2; +import android.test.suitebuilder.annotation.MediumTest; +import android.widget.TextView; +import com.android.tests.libdeps.MainActivity; +import com.google.common.base.Splitter; + +/** + * + */ +public class MainActivityTest extends ActivityInstrumentationTestCase2 { + + private TextView mLib1TextView1; + + public MainActivityTest() { + super(MainActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + final MainActivity a = getActivity(); + // ensure a valid handle to the activity has been returned + assertNotNull(a); + + mLib1TextView1 = (TextView) a.findViewById(R.id.lib1_text1); + } + + /** + * The name 'test preconditions' is a convention to signal that if this + * test doesn't pass, the test case was not set up properly and it might + * explain any and all failures in other tests. This is not guaranteed + * to run before other tests, as junit uses reflection to find the tests. + */ + @MediumTest + public void testPreconditions() { + assertNotNull(mLib1TextView1); + + // use some of Guava's class as they should be accessible through the + // classpath from the library + Iterable segments = Splitter.on("-").split(mLib1TextView1.getText()); + assertEquals("SUCCESS", segments.iterator().next()); + } +} diff --git a/tests/libTestDep/src/main/AndroidManifest.xml b/tests/libTestDep/src/main/AndroidManifest.xml new file mode 100644 index 0000000..00deb5c --- /dev/null +++ b/tests/libTestDep/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/libTestDep/src/main/java/com/android/tests/libdeps/MainActivity.java b/tests/libTestDep/src/main/java/com/android/tests/libdeps/MainActivity.java new file mode 100644 index 0000000..ab764d9 --- /dev/null +++ b/tests/libTestDep/src/main/java/com/android/tests/libdeps/MainActivity.java @@ -0,0 +1,15 @@ +package com.android.tests.libdeps; + +import android.app.Activity; +import android.os.Bundle; + +import com.android.tests.libdeps.R; + +public class MainActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.lib1_main); + } +} diff --git a/tests/libTestDep/src/main/res/drawable-hdpi/ic_launcher.png b/tests/libTestDep/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..8074c4c Binary files /dev/null and b/tests/libTestDep/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/tests/libTestDep/src/main/res/drawable-ldpi/ic_launcher.png b/tests/libTestDep/src/main/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000..1095584 Binary files /dev/null and b/tests/libTestDep/src/main/res/drawable-ldpi/ic_launcher.png differ diff --git a/tests/libTestDep/src/main/res/drawable-mdpi/ic_launcher.png b/tests/libTestDep/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..a07c69f Binary files /dev/null and b/tests/libTestDep/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/tests/libTestDep/src/main/res/layout/lib1_main.xml b/tests/libTestDep/src/main/res/layout/lib1_main.xml new file mode 100644 index 0000000..06ec124 --- /dev/null +++ b/tests/libTestDep/src/main/res/layout/lib1_main.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/tests/libTestDep/src/main/res/values/strings.xml b/tests/libTestDep/src/main/res/values/strings.xml new file mode 100644 index 0000000..8d20610 --- /dev/null +++ b/tests/libTestDep/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + + + LibsTest-lib1 + SUCCESS-LIB1 + + \ No newline at end of file -- cgit v1.2.3