Change R class package android/eclipse
Im working on a little interface in android and when I run it the "xxx开发者_如何学编程 application has stopped unexpectedly" appears. Im looking for posible errors but I don't find anything.
Anyway I would like to change the R class package name, when I refactor->rename it eclipse generates another one in the old package,even if I delete that package eclipse generates it again, I can't get rid of it!
To change the package name of the generated R
class, change the package
property of the <manifest>
tag in AndroidManifest.xml
It could be possible by customizing the aapt tools command line. aapt supports the --custom-package option that specifies the package where R class will be generated.
Using ANT, this can be achieved this way:
<exec executable="aapt" failonerror="true">
<arg value="package" />
<arg value="-m" />
<arg value="-J" />
<arg path="${gen.absolute.dir}" />
<arg value="-M" />
<arg path="AndroidManifest.xml" />
<arg value="-I" />
<arg path="${android.jar}" />
<arg value="-A" />
<arg path="${asset.absolute.dir}" />
<arg value="-S" />
<arg path="${resource.absolute.dir}" />
<arg value="--custom-package" />
<arg value="my.custom.package" />
</exec>
I have customized an ant script so that I can change the package name for R.java when building my application. What I've did is to override the -code-gen target and modified the projectLibrariesPackageName attribute when -code-gen is executing aapt. (one alternative is to change the build build.xml that eclipse is using, I think it can be found in /tools/ant/build.xml )
<!-- Code Generation: compile resources (aapt -> R.java), aidl, renderscript -->
<target name="-code-gen">
<do-only-if-manifest-hasCode
elseText="hasCode = false. Skipping aidl/renderscript/R.java">
<echo>...........</echo>
<echo>Handling aidl files...</echo>
<aidl executable="${aidl}" framework="${android.aidl}"
genFolder="${gen.absolute.dir}">
<source path="${source.absolute.dir}"/>
</aidl>
<!-- renderscript generates resources so it must be called before aapt -->
<echo>...........</echo>
<echo>Handling RenderScript files...</echo>
<renderscript executable="${renderscript}"
framework="${android.rs}"
genFolder="${gen.absolute.dir}"
resFolder="${resource.absolute.dir}/raw"
targetApi="${target.api}">
<source path="${source.absolute.dir}"/>
</renderscript>
<echo>...........</echo>
<echo>Handling Resources...</echo>
<aapt executable="${aapt}"
command="package"
verbose="${verbose}"
manifest="AndroidManifest.xml"
androidjar="${android.jar}"
rfolder="${gen.absolute.dir}"
nonConstantId="${android.library}"
projectLibrariesResName="project.libraries.res"
projectLibrariesPackageName="package.internal"> <!-- Put custom package name here -->
<res path="${resource.absolute.dir}" />
</aapt>
</do-only-if-manifest-hasCode>
</target>
- Look at your LogCat. It should have the stack trace of your error.
- To see your LogCat from Eclipse, go to Window > Show View > Other > Android > LogCat.
- To see your LogCat from the command line, go to your SDK/tools folder and run "adb logcat"
- It's not possible to change the R class package.
Change your Perspective in Eclips from Java Perspective (Top Right Corner) to DDMS Perspective. There you will find the LogCat to View Errors in your Android Build.
Check it and then Post that errors so we can help you.
精彩评论