Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-16320] Android: Integrate v7 compat library #5314

Merged
merged 10 commits into from
Feb 6, 2014
Merged
  •  
  •  
  •  
19 changes: 18 additions & 1 deletion android/build/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Common ant tasks and macros for building Android-based Titanium modules and proj
<fileset dir="${ti.build.dir}/lib" includes="**/*.jar"/>
</path>

<property name="v7appcompat.project.dir" location="${ti.android.root}/modules/appcompat"/>
<property name="titanium.project.dir" location="${ti.android.root}/titanium"/>
<property name="kroll.apt.project.dir" location="${ti.android.root}/kroll-apt"/>
<property name="kroll.common.project.dir" location="${ti.android.root}/runtime/common"/>
Expand Down Expand Up @@ -143,6 +144,7 @@ Common ant tasks and macros for building Android-based Titanium modules and proj
<path id="titanium.path">
<pathelement path="${dist.classes.dir}/titanium"/>
<fileset dir="${titanium.project.dir}/lib" includes="**/*.jar"/>
<fileset dir="${v7appcompat.project.dir}/lib" includes="**/*.jar"/>
</path>

<macrodef name="build.project">
Expand Down Expand Up @@ -526,6 +528,13 @@ Common ant tasks and macros for building Android-based Titanium modules and proj
<zip destfile="${dist.dir}/titanium-@{name}.res.zip">
<zipfileset dir="${modules.dir}/@{name}" includes="res/**"/>
</zip>
<ti.modulePackage json="${dependency.json}" module="@{name}" property="titanium-@{name}.respackage"/>
<if>
<isset property="titanium-@{name}.respackage"/>
<then>
<echo file="${dist.dir}/titanium-@{name}.respackage" append="false">${titanium-@{name}.respackage}</echo>
</then>
</if>
</sequential>
</macrodef>

Expand Down Expand Up @@ -623,6 +632,7 @@ Common ant tasks and macros for building Android-based Titanium modules and proj
<taskdef classname="org.appcelerator.titanium.ant.StringTask" name="ti.string" classpathref="ti.build.path"/>
<taskdef classname="org.appcelerator.titanium.ant.UpdateModulesJSONTask" name="ti.updateModulesJSON" classpathref="ti.build.path"/>
<taskdef classname="org.appcelerator.titanium.ant.JSONMap" name="ti.jsonMap" classpathref="ti.build.path"/>
<taskdef classname="org.appcelerator.titanium.ant.ModulePackageTask" name="ti.modulePackage" classpathref="ti.build.path"/>
</sequential>
</macrodef>

Expand Down Expand Up @@ -650,7 +660,14 @@ Common ant tasks and macros for building Android-based Titanium modules and proj
<if>
<istrue value="${@{module}.res.avail}"/>
<then>
<zip.module.res name="@{module}"/>
<fileset dir="${modules.dir}/@{module}/res" id="fileset"/>
<pathconvert refid="fileset" property="@{module}.res.empty" setonempty="false"/>
<if>
<isset property="@{module}.res.empty"/>
<then>
<zip.module.res name="@{module}"/>
</then>
</if>
</then>
</if>
</sequential>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.appcelerator.titanium.ant;

import java.util.Map;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class ModulePackageTask extends Task {

protected String json,module,property;

@Override
public void execute() throws BuildException {
if (json == null) {
throw new BuildException("No JSON file specified for " + getTaskName());
}
if (module == null) {
throw new BuildException("No module specified for " + getTaskName());
}

if (property == null) {
throw new BuildException("No property specified for " + getTaskName());
}


TiModuleDependencies deps = new TiModuleDependencies(json);
Map<String,String> theMaps = deps.getModulePackages();
if(theMaps.containsKey(module)) {
String theVal = theMaps.get(module);
if(theVal != null && theVal.length() > 0) {
getProject().setProperty(property, theVal);
} else {
System.out.println("No valid path defined for module "+module);
}
}
}

public String getJson() {
return json;
}

public void setJson(String json) {
this.json = json;
}

public String getProperty() {
return property;
}

public void setProperty(String property) {
this.property = property;
}

public String getModule() {
return module;
}

public void setModule(String module) {
this.module = module;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public Map<String, List<String>> getDependencies() {
return (Map<String, List<String>>)map.get("dependencies");
}

public Map<String, String> getModulePackages() {
return (Map<String, String>)map.get("modulepackage");
}

public Collection<String> getModules() {
return getDependencies().keySet();
}
Expand Down
67 changes: 54 additions & 13 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,7 @@ AndroidBuilder.prototype.processTiSymbols = function processTiSymbols(next) {
moduleJarMap = {},
tiNamespaces = this.tiNamespaces = {}, // map of namespace => titanium functions (i.e. ui => createWindow)
jarLibraries = this.jarLibraries = {},
resPackages = this.resPackages = {},
appModules = this.appModules = [], // also used in the App.java template
appModulesMap = {},
customModules = this.customModules = [],
Expand Down Expand Up @@ -2749,9 +2750,6 @@ AndroidBuilder.prototype.processTiSymbols = function processTiSymbols(next) {
depMap.dependencies[namespace] && depMap.dependencies[namespace].forEach(addTitaniumLibrary, this);
}

// force the network lib since it's needed for tiverify and analytics
addTitaniumLibrary.call(this, 'network');

// get all required titanium modules
depMap.required.forEach(addTitaniumLibrary, this);

Expand Down Expand Up @@ -2919,7 +2917,14 @@ AndroidBuilder.prototype.copyModuleResources = function copyModuleResources(next

var tasks = Object.keys(this.jarLibraries).map(function (jarFile) {
return function (done) {
var resFile = jarFile.replace(/\.jar$/, '.res.zip');
var resFile = jarFile.replace(/\.jar$/, '.res.zip'),
resPkgFile = jarFile.replace(/\.jar$/, '.respackage');

if (fs.existsSync(resPkgFile) && fs.existsSync(resFile)) {
this.resPackages[resFile] = fs.readFileSync(resPkgFile).toString().split('\n').shift().trim();
return done();
}

if (!fs.existsSync(jarFile) || !fs.existsSync(resFile)) return done();
this.logger.info(__('Extracting module resources: %s', resFile.cyan));

Expand Down Expand Up @@ -3561,11 +3566,8 @@ AndroidBuilder.prototype.packageApp = function packageApp(next) {

done();
}.bind(this));
});

aaptHook(
this.androidInfo.sdk.executables.aapt,
[
}),
args = [
'package',
'-f',
'-m',
Expand All @@ -3576,10 +3578,49 @@ AndroidBuilder.prototype.packageApp = function packageApp(next) {
'-I', this.androidTargetSDK.androidJar,
'-I', path.join(this.platformPath, 'titanium.jar'),
'-F', this.ap_File
],
{},
next
);
];

function runAapt() {
aaptHook(
this.androidInfo.sdk.executables.aapt,
args,
{},
next
);
}

if (!Object.keys(this.resPackages).length) {
return runAapt();
}

args.push('--auto-add-overlay');

var namespaces = '';
Object.keys(this.resPackages).forEach(function(resFile){
console.log(resFile);
namespaces && (namespaces+=':');
namespaces += this.resPackages[resFile];
}, this);

args.push('--extra-packages', namespaces);

appc.async.series(this, Object.keys(this.resPackages).map(function (resFile) {
return function (cb) {
var namespace = this.resPackages[resFile],
tmp = temp.path();

appc.zip.unzip(resFile, tmp, {}, function (ex) {
if (ex) {
this.logger.error(__('Failed to extract module resource zip: %s', resFile.cyan) + '\n');
process.exit(1);
}

args.push('-S', tmp+'/res');

cb();
}.bind(this));
};
}), runAapt);
};

AndroidBuilder.prototype.compileJavaClasses = function compileJavaClasses(next) {
Expand Down
15 changes: 11 additions & 4 deletions android/dependency.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"min_api_level": "10",
"dependencies":
{
"appcompat":[],
"accelerometer":[],
"analytics":[],
"android":[],
Expand All @@ -17,21 +18,27 @@
"media":["filesystem"],
"network":["xml"],
"platform":[],
"ui":["filesystem","media"],
"ui":["filesystem","media","appcompat"],
"utils":[],
"xml":[]
},
"required": ["analytics","android","app","ui","locale"],
"required": ["analytics","android","app","ui","locale","network"],
"libraries":
{
"android":["jaxen-1.1.1.jar","ti-commons-codec-1.3.jar","kroll-common.jar","titanium.jar"],
"xml":["jaxen-1.1.1.jar"],
"ui":["android-support-v4.jar", "nineoldandroids-appc-2.4.0.jar"],
"network":["thirdparty.jar"]
"ui":["nineoldandroids-appc-2.4.0.jar"],
"network":["thirdparty.jar"],
"appcompat":["android-support-v4.jar", "android-support-v7-appcompat.jar"]
},
"runtimes":
{
"v8":["kroll-v8.jar"],
"defaultRuntime":"v8"
},
"modulepackage":
{
"appcompat":"android.support.v7.appcompat",
"ui":"ti.modules.titanium.ui"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ protected void genModules(String modulesDestDir)

modulesJSON.put(name, moduleNames);
}

//Hack in the appcompat module for now. revisit later.
ArrayList<String> appCompatHack = new ArrayList<String>();
appCompatHack.add("appcompat");
modulesJSON.put("titanium-appcompat.jar", appCompatHack);

File modules = new File(modulesDestDir, "modules.json");

try {
Expand Down
2 changes: 1 addition & 1 deletion android/modules/accelerometer/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

android.library=true
# Project target.
target=Google Inc.:Google APIs:10
target=Google Inc.:Google APIs:16
android.library.reference.1=../../runtime/common
android.library.reference.2=../../titanium
2 changes: 1 addition & 1 deletion android/modules/analytics/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

android.library=true
# Project target.
target=Google Inc.:Google APIs:10
target=Google Inc.:Google APIs:16
android.library.reference.1=../../runtime/common
android.library.reference.2=../../titanium
2 changes: 1 addition & 1 deletion android/modules/android/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

android.library=true
# Project target.
target=android-14
target=Google Inc.:Google APIs:16
android.library.reference.1=../../runtime/common
android.library.reference.2=../../titanium
2 changes: 1 addition & 1 deletion android/modules/app/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

android.library=true
# Project target.
target=Google Inc.:Google APIs:10
target=Google Inc.:Google APIs:16
android.library.reference.1=../../runtime/common
android.library.reference.2=../../titanium
11 changes: 11 additions & 0 deletions android/modules/appcompat/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry exported="true" kind="lib" path="lib/android-support-v4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/android-support-v7-appcompat.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
33 changes: 33 additions & 0 deletions android/modules/appcompat/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android-support-v7-appcompat</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
20 changes: 20 additions & 0 deletions android/modules/appcompat/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.support.v7.appcompat">
<uses-sdk android:minSdkVersion="7"/>
<application />
</manifest>
10 changes: 10 additions & 0 deletions android/modules/appcompat/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Library Project including compatibility ActionBar.

This can be used by an Android project to provide
access to ActionBar on applications running on API 7+.

There is technically no source, but the src folder is necessary
to ensure that the build system works. The content is actually
located in libs/android-support-v7-appcompat.jar.
The accompanying resources must also be included in the application.

3 changes: 3 additions & 0 deletions android/modules/appcompat/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<project name="appcompat" default="build">
<import file="../../build/build-module.xml"/>
</project>
Binary file not shown.
Binary file not shown.