Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/android/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _collect_jars(self, paths):
return jar_files

def compile_java(self, source_dirs, output_dir, extra_jars=[],
debug=False, target='1.5'):
debug=False, target='1.6'):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see such a change, if necessary, in a separate commit.

"""Compile all *.java files in ``source_dirs`` (a list of
directories) and store the class files in ``output_dir``.

Expand Down Expand Up @@ -327,6 +327,7 @@ def compile(self, manifest, project_dir, source_dirs, resource_dir,
For directories that you do not specifiy a tenmporary directory
will be used and deleted after the build.
"""

to_delete = []
if not source_gen_dir:
source_gen_dir = tempfile.mkdtemp()
Expand Down Expand Up @@ -367,6 +368,7 @@ def pack_resources(self, manifest, resource_dir, asset_dir=None,
if not output:
_, output = tempfile.mkstemp(suffix='.ap_')
output = path.abspath(output)

kwargs = dict(
command='package',
manifest=manifest,
Expand Down Expand Up @@ -431,7 +433,7 @@ def align(self, apk, output=None):
return Apk(self, outfile)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good change, though ideally, it would also be a separate commit.


def get_platform(sdk_path, ndk_dir, target=None):
def get_platform(sdk_path, target=None, ndk_dir=None):
"""Return path and filename information for the given SDK target.

If no target is given, the most recent target is chosen.
Expand Down Expand Up @@ -563,13 +565,39 @@ def __init__(self, manifest, name=None, platform=None, sdk_dir=None,
if target is None:
target = self.manifest_parsed.find('uses-sdk')\
.attrib['{http://schemas.android.com/apk/res/android}targetSdkVersion']
platform = get_platform(sdk_dir, ndk_dir, target)
platform = get_platform(sdk_dir, ndk_dir=ndk_dir, target=target)

self.platform = platform

# Optional values
self.extra_source_dirs = []
self.extra_jars = []
self.extra_resource_dirs = []

# project directory needed for library project dependecies
if project_dir != None:
# get project path
f = open(os.path.join(project_dir,"project.properties"))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible this file doesn't exist, if Eclipse isn't used. There should be an alternative way to specify library projects, via an attribute for example, where I can list paths to library projects manually. Also, is it possible that a library projects references other library projects (recursion?)

lines = f.readlines()

# workspace dir
fs = project_dir.split("/")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this part doing? I don't understand... Maybe a comment should explain it.

fs.pop()

workspace_path = "/"

for fn in fs:
workspace_path = os.path.join(workspace_path,fn)

# search for library projects in project.properties
for line in lines:
if line.startswith("android.library"):
lname = line.split("/")[-1].rstrip()
library_project = os.path.join(workspace_path, lname)

self.extra_source_dirs.append(os.path.join(library_project,"src"))
self.extra_jars.append(os.path.join(library_project,"libs"))
self.extra_resource_dirs.append(os.path.join(library_project,"res"))

# if no name is given, inspect the manifest
self.name = name or self.manifest_parsed.attrib['package']
Expand All @@ -589,7 +617,7 @@ def compile(self):
manifest=self.manifest,
project_dir = self.project_dir,
source_dirs=[self.source_dir] + self.extra_source_dirs,
resource_dir=self.resource_dir,
resource_dir=[self.resource_dir] + self.extra_resource_dirs,
source_gen_dir=self.gen_dir,
class_gen_dir=path.join(self.out_dir, 'classes'),
extra_jars=only_existing([self.lib_dir])+self.extra_jars
Expand Down Expand Up @@ -617,7 +645,7 @@ def build(self, output=None, config=None, package_name=None,
self.out_dir, '%s.%s.ap_' % (self.name, config))
kwargs = dict(
manifest=self.manifest,
resource_dir=self.resource_dir,
resource_dir=[self.resource_dir] + self.extra_resource_dirs,
configurations=config,
output=resource_filename,
package_name=package_name,
Expand Down
45 changes: 43 additions & 2 deletions src/android/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import sys
import os
import subprocess
import collections


__all__ = ('ProgramFailedError', 'Aapt', 'Aidl', 'LlvmRs', 'ApkBuilder',
Expand Down Expand Up @@ -74,6 +75,13 @@ def __call__(self, arguments, env=None, shell=False):
Child implementations must not forget to pass this return value
along to their caller.
"""
<<<<<<< HEAD
cmdline = " ".join([self.executable] + arguments)

process = subprocess.Popen([self.executable] + arguments,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
=======
cmdline = [self.executable] + arguments
if shell and not sys.platform=="win32":
# This is required for scripts that lack the +x flag
Expand All @@ -89,6 +97,7 @@ def __call__(self, arguments, env=None, shell=False):
env=custom_env,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
>>>>>>> upstream/master
process.wait()
if process.returncode != 0:
raise ProgramFailedError(
Expand Down Expand Up @@ -138,7 +147,10 @@ def __call__(self, command, manifest=None, resource_dir=None,
args = [command]
self.extend_args(args, ['-m'], make_dirs)
self.extend_args(args, ['-M', manifest])
self.extend_args(args, ['-S', resource_dir])

for item in resource_dir:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backwards-compatibility, allow resource_dir to be a list, or a single item.

self.extend_args(args, ['-S', item])

self.extend_args(args, ['-A', asset_dir])
self.extend_args(args, ['-c', configurations])
if overwrite_version_code:
Expand All @@ -152,6 +164,9 @@ def __call__(self, command, manifest=None, resource_dir=None,
self.extend_args(args, ['-F', apk_output])
self.extend_args(args, ['-J', r_output])
self.extend_args(args, ['-f'], overwrite)
self.extend_args(args, ["--auto-add-overlay"])
self.extend_args(args, ["--no-crunch"])

return Program.__call__(self, args)


Expand Down Expand Up @@ -181,7 +196,10 @@ def __call__(self, aidl_file, preprocessed=None, search_path=None,
self.extend_args(args, [aidl_file])
return Program.__call__(self, args)

<<<<<<< HEAD
=======

>>>>>>> upstream/master
class LlvmRs(Program):
"""Interface to the command line llvm renderscript compiler, ``llvm-rs-cc``
"""
Expand All @@ -208,6 +226,7 @@ def __call__(self, project_path):
"""
args = []
self.extend_args(args, ["-C", project_path])

return Program.__call__(self, args)

class NdkClean(Program):
Expand Down Expand Up @@ -270,12 +289,33 @@ def __call__(self, files, output=None):
"""
files
A set of class files, .zip/.jar/.apk archives or
directories.
directories.q
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous character.


output
Target output file (--output).
"""
args = ['--dex']

jar_list = []
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know; this seems overly complicated; but also possibly wrong. From what I can tell it is supposed to remove duplicate jars (why are there duplicates in the first place?).

I see two possible problems:

  • First, since it only looks at the file basename, is that good enough? Couldn't there be two jar files that have the same name, but are actually different?
  • Second, it seems to only remove a single duplicate; if there are three identical jars, only one will be removed, from what I can tell. That is, if I'm reading the code correctly.

How does Android's Ant build process deal with this?

for item in files:
if item.endswith(".jar"):
fname = item.split('/')
fname = fname[-1]

jar_list.append(fname)

counter_list = collections.Counter(jar_list)
repeated_elements = [i for i in counter_list if counter_list[i] > 1]

for jar in files:
fname = jar.split("/")
fname = fname[-1]

for item in repeated_elements:
if item == fname:
files.remove(jar)
repeated_elements.remove(item)

self.extend_args(args, ["--output=%s" % output])
args.extend(files)
return Program.__call__(self, args)
Expand Down Expand Up @@ -313,6 +353,7 @@ def __call__(self, outputfile, dex=None, zips=[], source_dirs=[],
args = [outputfile]
args.extend(['-u']) # unsigned
self.extend_args(args, ['-f', dex])

for zip in zips:
args.extend(['-z', zip])
for source_dir in source_dirs:
Expand Down