forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate the Android SDK, android-library
This is the 2nd part of splitting up pantsbuild#2040. This follows up on pantsbuild#2467 (adding unpack_libraries task and android_library). This adds the google and android m2 repos from the SDK into ivysettings.xml. AndroidLibraries are unpacked once per artifact in UnpackLibraries. The unpack .class files are packed into the android_binary's classes.dex file. The android_library BUILD files allow for include/exclude patterns, those patterns are filtered against during the repack in DxCompile. This allows us several advantages: * each artifact is unpacked only once, no matter how many dependees or include patterns * therefore each class file has a static path, so duplicate class files (allowed in the build but illegal to pass to dx tool) are easily detected * Version conflicts are detected by class name(which is how it is done within the dx tool) and can raise a useful exception. Processing the resources in AaptGen is moved off of the codegen backend. The gentarget for AaptGen is the AndroidBinary. Each android_library in the transitive closure needs to be compiled against the binary's target_sdk. Libraries are passed to the aapt tool once for every SDK version they support. This also adds lots of testing for big parts of the android pipeline and a couple of new example projects to show the new functionality. Problems/Followups * Duplicated code in UnpackJars and UnpackLibraries, including fingerprint handling. Pulling up an Unpack base class or refactor to FileUtil or something (this includes Fingerprint strategy) * No invalidation framework for aapt_gen yet. It doesn't currently distinguish between libraries that need to be processed by multiple SDKs. References pantsbuild#1390 References pantsbuild#10 Testing Done: Travis passed Bugs closed: 1866 Reviewed at https://rbcommons.com/s/twitter/r/2528/
- Loading branch information
Showing
36 changed files
with
1,306 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
android_dependency(name='android-support-v4', | ||
jars = [ | ||
jar(org='com.android.support', name='support-v4', rev='22.0.0'), | ||
], | ||
) | ||
|
||
android_dependency(name='appcompat-v7', | ||
jars = [ | ||
jar(org='com.android.support', name='appcompat-v7', rev='22.0.0'), | ||
], | ||
) | ||
|
||
android_dependency(name='google-play-services', | ||
jars=[ | ||
jar(org='com.google.android.gms', name='play-services', rev='7.0.0'), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.pantsbuild.examples.example_library"> | ||
<uses-sdk android:minSdkVersion="9" /> | ||
|
||
<application> | ||
<meta-data | ||
android:name="org.pantsbuild.examples.example_library.ExampleLibrary" /> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
android_library( | ||
name='example_library', | ||
manifest='AndroidManifest.xml', | ||
libraries=['3rdparty/android:android-support-v4'], | ||
include_patterns=[ | ||
'android/**/*.class', | ||
], | ||
dependencies=[ | ||
':gms-library', | ||
':resources', | ||
], | ||
) | ||
|
||
android_resources( | ||
name='resources', | ||
manifest='AndroidManifest.xml', | ||
resource_dir='res' | ||
) | ||
|
||
android_library( | ||
name='gms-library', | ||
libraries=['3rdparty/android:google-play-services'], | ||
include_patterns=[ | ||
'**/*.class', | ||
], | ||
dependencies = [ | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
--> | ||
<resources> | ||
<string name="appName">Hello Pants</string> | ||
<string name="hello">Hello world!</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
android_binary( | ||
name='hello_with_library', | ||
sources=rglobs('main/src/*.java'), | ||
manifest='main/AndroidManifest.xml', | ||
dependencies = [ | ||
'examples/src/android/example_library', | ||
':resources', | ||
], | ||
) | ||
|
||
android_resources( | ||
name='resources', | ||
manifest='AndroidManifest.xml', | ||
resource_dir='main/res' | ||
) | ||
|
33 changes: 33 additions & 0 deletions
33
examples/src/android/hello_with_library/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.pantsbuild.examples.hello_with_library" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="8" | ||
android:targetSdkVersion="21" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher_hdpi" | ||
android:label="@string/appName"> | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name="org.pantsbuild.examples.hello_with_library.HelloLibrary" | ||
android:configChanges="orientation|keyboardHidden|screenSize" | ||
android:label="@string/appName"> | ||
android:theme="@style/FullscreenTheme" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Binary file added
BIN
+9.18 KB
examples/src/android/hello_with_library/main/res/drawable/ic_launcher_hdpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
examples/src/android/hello_with_library/main/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
--> | ||
<resources> | ||
<string name="appName">Hello Library</string> | ||
<string name="library_greeting">This string is part of the example library!</string> | ||
</resources> |
30 changes: 30 additions & 0 deletions
30
.../hello_with_library/main/src/org/pantsbuild/examples/hello_with_library/HelloLibrary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// coding=utf-8 | ||
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
// Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
package org.pantsbuild.examples.hello_with_library; | ||
|
||
import android.app.Activity; | ||
import android.content.res.Resources; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.widget.TextView; | ||
|
||
public class HelloLibrary extends Activity { | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
TextView textView = new TextView(this); | ||
|
||
String text = getResources().getString(R.string.hello); | ||
textView.setText(text); | ||
|
||
// Toy demonstration of using an android_library comprised of a jar and associated resources. | ||
String greeting = getResources().getString(R.string.library_greeting); | ||
textView.setText(greeting); | ||
|
||
setContentView(textView); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.