diff options
4 files changed, 92 insertions, 8 deletions
diff --git a/anttasks/src/com/android/ant/PropertyByReplaceTask.java b/anttasks/src/com/android/ant/PropertyByReplaceTask.java new file mode 100644 index 0000000..a0707de --- /dev/null +++ b/anttasks/src/com/android/ant/PropertyByReplaceTask.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package com.android.ant; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.Property; + +/** + * Task to do simple char to char replacement on strings. + */ +public class PropertyByReplaceTask extends Property { + + private String mInput; + private char mInputChar; + private char mWithChar; + + public void setInput(String input) { + mInput = input; + } + + public void setReplace(char inputChar) { + mInputChar = inputChar; + } + + public void setWith(char withChar) { + mWithChar = withChar; + } + + @Override + public void execute() throws BuildException { + setValue(mInput.replace(mInputChar, mWithChar)); + super.execute(); + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java index e963af8..c61f738 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/builders/PostCompilerBuilder.java @@ -35,6 +35,7 @@ import com.android.ide.eclipse.adt.internal.project.LibraryClasspathContainerIni import com.android.ide.eclipse.adt.internal.project.ProjectHelper; import com.android.ide.eclipse.adt.internal.sdk.ProjectState; import com.android.ide.eclipse.adt.internal.sdk.Sdk; +import com.android.ide.eclipse.adt.io.IFileWrapper; import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.SdkConstants; import com.android.sdklib.build.ApkCreationException; @@ -42,6 +43,7 @@ import com.android.sdklib.build.DuplicateFileException; import com.android.sdklib.build.IArchiveBuilder; import com.android.sdklib.build.SealedApkException; import com.android.sdklib.internal.build.DebugKeyProvider.KeytoolException; +import com.android.sdklib.xml.AndroidManifest; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -436,9 +438,14 @@ public class PostCompilerBuilder extends BaseBuilder { if (DEBUG) { System.out.println("\tupdating jar!"); } + + // resource to the AndroidManifest.xml file + IFile manifestFile = project.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML); + String appPackage = AndroidManifest.getPackage(new IFileWrapper(manifestFile)); + IFolder javaOutputFolder = BaseProjectHelper.getJavaOutputFolder(project); - writeLibraryPackage(jarIFile, project, javaOutputFolder, + writeLibraryPackage(jarIFile, project, appPackage, javaOutputFolder, referencedJavaProjects); saveProjectBooleanProperty(PROPERTY_CONVERT_TO_DEX, mConvertToDex = false); @@ -786,12 +793,16 @@ public class PostCompilerBuilder extends BaseBuilder { private static class JarBuilder implements IArchiveBuilder { private static Pattern R_PATTERN = Pattern.compile("R(\\$.*)?\\.class"); //$NON-NLS-1$ + private static Pattern MANIFEST_PATTERN = Pattern.compile("Manifest(\\$.*)?\\.class"); //$NON-NLS-1$ + private static String BUILD_CONFIG_CLASS = "BuildConfig.class"; //$NON-NLS-1$ private final byte[] buffer = new byte[1024]; private final JarOutputStream mOutputStream; + private final String mAppPackage; - JarBuilder(JarOutputStream outputStream) { + JarBuilder(JarOutputStream outputStream, String appPackage) { mOutputStream = outputStream; + mAppPackage = appPackage.replace('.', '/'); } public void addFile(IFile file, IFolder rootFolder) throws ApkCreationException { @@ -800,9 +811,15 @@ public class PostCompilerBuilder extends BaseBuilder { return; } - // we don't package any R[$*] classes. + IPath packageApp = file.getParent().getFullPath().makeRelativeTo( + rootFolder.getFullPath()); + String name = file.getName(); - if (R_PATTERN.matcher(name).matches()) { + // we don't package any R[$*] classes or buildconfig + if (mAppPackage.equals(packageApp.toString()) && + (BUILD_CONFIG_CLASS.equals(name) || + MANIFEST_PATTERN.matcher(name).matches() || + R_PATTERN.matcher(name).matches())) { return; } @@ -881,8 +898,8 @@ public class PostCompilerBuilder extends BaseBuilder { return true; } - private void writeLibraryPackage(IFile jarIFile, IProject project, IFolder javaOutputFolder, - List<IJavaProject> referencedJavaProjects) { + private void writeLibraryPackage(IFile jarIFile, IProject project, String appPackage, + IFolder javaOutputFolder, List<IJavaProject> referencedJavaProjects) { JarOutputStream jos = null; try { @@ -893,7 +910,7 @@ public class PostCompilerBuilder extends BaseBuilder { jos = new JarOutputStream( new FileOutputStream(jarIFile.getLocation().toFile()), manifest); - JarBuilder jarBuilder = new JarBuilder(jos); + JarBuilder jarBuilder = new JarBuilder(jos, appPackage); // write the class files writeClassFilesIntoJar(jarBuilder, javaOutputFolder, javaOutputFolder); diff --git a/files/ant/build.xml b/files/ant/build.xml index 05dfdec..a54efbb 100644 --- a/files/ant/build.xml +++ b/files/ant/build.xml @@ -108,6 +108,10 @@ classname="com.android.ant.IfElseTask" classpathref="android.antlibs" /> + <taskdef name="propertybyreplace" + classname="com.android.ant.PropertyByReplaceTask" + classpathref="android.antlibs" /> + <!-- Emma configuration --> <property name="emma.dir" value="${sdk.dir}/tools/lib" /> <path id="emma.lib"> @@ -690,8 +694,12 @@ <echo>Custom jar packaging exclusion: ${android.package.excludes}</echo> </then> </if> + + <propertybyreplace name="manifest.package.path" input="${manifest.package}" replace="." with="/" /> + <jar destfile="${out.library.jar.file}"> - <fileset dir="${out.classes.absolute.dir}" excludes="**/R.class **/R$*.class"/> + <fileset dir="${out.classes.absolute.dir}" + excludes="${manifest.package.path}/R.class ${manifest.package.path}/R$*.class ${manifest.package.path}/Manifest.class ${manifest.package.path}/Manifest$*.class ${manifest.package.path}/BuildConfig.class"/> <fileset dir="${source.absolute.dir}" excludes="**/*.java ${android.package.excludes}" /> </jar> </then> diff --git a/testapps/customViewTest/libWithCustomView/AndroidManifest.xml b/testapps/customViewTest/libWithCustomView/AndroidManifest.xml index 7e5c61a..89cff95 100644 --- a/testapps/customViewTest/libWithCustomView/AndroidManifest.xml +++ b/testapps/customViewTest/libWithCustomView/AndroidManifest.xml @@ -4,4 +4,15 @@ android:versionCode="1" android:versionName="1.0" > + <permission + android:name="com.foo.mypermission" + android:description="@string/app_name" + android:label="@string/app_name" > + </permission> + <permission + android:name="com.foo.mypermission2" + android:description="@string/app_name" + android:label="@string/app_name" > + </permission> + </manifest>
\ No newline at end of file |