如何强制 eclipse 在每次构建时更新我的​​硬件

How do I force eclipse to update the apk on my hardware device with each build?(如何强制 eclipse 在每次构建时更新我的​​硬件设备上的 apk?)

本文介绍了如何强制 eclipse 在每次构建时更新我的​​硬件设备上的 apk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我更改某些代码、保存并运行,它会运行程序的最新版本,而不是我刚刚保存的.我可以让它更新的唯一方法是清理项目,构建项目,然后运行项目.有什么方法可以避免这种乏味吗?

If I change some code, save, and Run, it runs the last version of the program, not what I just saved. The only way I can make it update is if I Clean the project, Build the project, and then Run the project. Is there some way to avoid this tedium?

推荐答案

我花了一些时间创建了两个虚拟项目(一个Android和一个Java)并玩了一下,最后想出了一个没有使用的解决方法经常但能够解决您的要求.

I spent some time create two dummy projects (one Android and one Java) and have a play with it, and finally come up with a workaround which is not used very often but able to solve your requirements.

首先,我会稍微解释一下您的问题(根据我的理解和我的尝试),以便其他人可以更清楚地了解这里发生的事情.

First, I will explain your question a bit more (based on my understanding and what I have tried) so that other people can have a more clear understand about what is happened here.

根据评论中的对话:

你能告诉我你在以下设置中有什么:project->properties->Builder?——苏达尔·尼玛兰

could you tell me what you have in following setting: project->properties->Builder ? – Sudar Nimalan

@SudarNimalan:我不确定这是您要问的,但是:有文字说配置此项目的构建器",在它下面是一个选项Java builder",它被选中(检查).– shino

@SudarNimalan: I am not sure this is what you are asking, but: there's text that says "Configure the builders for this project", and under it is a single option, "Java builder", which is selected (checked). – shino

对于android项目,应该有,Android Resource Manager",Android Pre Compiler",Java Builder",Android Package Builder"按照这个顺序,你会添加这些并尝试吗?——苏达尔·尼玛兰

for android project, there should be, "Android Resource Manager", "Android Pre Compiler", "Java Builder", "Android Package Builder" in this order, chould you add those and try? – Sudar Nimalan

@SudarNimalan:我欠你一个道歉;我确实有这四个组成部分.我的项目"分为 4 个项目 - core"、core-android"、core-desktop"和core-html".这有点奇怪,因为我使用 libGDX 项目设置 UI 进行了设置,当我回答您的问题时,我正在查看核心"项目.我的core-android"项目有所有四个(按此顺序),这是我的问题中存在问题的一个.– shino

@SudarNimalan: I owe you an apology; I do have those four components. My "project" is split into 4 projects - "core", "core-android", "core-desktop", and "core-html". It's a little weird because I set it up with the libGDX project setup UI, and I was looking at the 'core' project when I answered your question. My 'core-android' project has all four (in that order), and it is the one that has the problem in my question. – shino

场景:

你有 4 个项目:

Scenario:

You have 4 project:

  • core:一个普通的java项目(这里是普通的纯java代码)
  • core-android:一个 Android 应用项目.
  • core-desktop:与被忽略的问题无关.
  • core-html:与问题无关,因此被忽略.

core-android 项目依赖于 core 项目,通过将 core 添加到 core-android 的构建路径 (Properties -> Java Build Path -> Projects -> Add ...) 和导出列表 (Properties ->; Java 构建路径 -> 排序和导出).

The core-android project has dependency on core project, by adding core to core-android's build path (Properties -> Java Build Path -> Projects -> Add ...) and export list (Properties -> Java Build Path -> Order and Export).

更改core中的一些代码并保存,运行core-android,eclipse安装最后编译的apk,而不是新的有变化的.

Change some code in core and save it, run core-android, eclipse install last compiled apk, not the new one with change.

这是预期的行为,您在 core-android 中引用核心项目的方式只会在 core 和 core-android、core-andorid 的自动构建脚本之间创建一个弱链接(或某种东西)不知道核心中所做的任何更改.您必须清理项目(只需要清理 core-android 项目),以便 Eclipse 可以删除现有的 apk(在 bin 目录下)并重新生成 apk(与核心的最新代码更改).

请注意,如果 core 是一个 Android 库项目,那么没有问题,如果 core 仅用于 core-android,这也可能是一种解决方法:将 Java 项目核心转为 Android 库项目.

Note that if core is an Android Library project, then there is no problem and your core-android project will aware any changes in core project (java code, android resource and etc), if core is only used in core-android, this could also be a workaround: turn Java project core into Android library project.

项目之间添加软链接还有另一种方式(不常用):

There is another way (not commonly used) for adding soft link between projects:

  1. 首先,您需要从 core-android 的构建路径中移除核心项目,这也会将其从导出和订单列表中移除.
  2. 右键core-android,选择Build Path ->链接源...添加 ../core/src 作为链接文件夹位置和 src-lib1 作为文件夹名称,请参阅最后的屏幕屏幕.

这在Package Explorer窗口中的core-android下创建了一个符号链接src-lib1,指向core的src foder,在文件系统中,你仍然有两个独立的项目文件夹.现在,如果您更改 core 中的一些代码并运行 core-android,Eclipse 将构建并安装最新的 apk.无需清理 core-android 项目.

This create a symbolic link src-lib1 under core-android in Package Explorer windows point to core's src foder, in the file system, you still have two separate project folder. Now if you change some code in core and run core-android, Eclipse will build and install latest apk. No need to clean core-android project.

链接源窗口:

包资源管理器的最终外观:

Final look in Package Explorer:

您应该始终将常规方法视为第一选择,毕竟手动清理项目与我上面描述的不寻常方法相比没什么大不了的.

You should always consider the normal approach as first option, after all, manual clean project is not a big deal compare to the unusual approach I described above.

这篇关于如何强制 eclipse 在每次构建时更新我的​​硬件设备上的 apk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何强制 eclipse 在每次构建时更新我的​​硬件

基础教程推荐