Eclipse:转换为 Dalvik 格式失败,错误 1

发布于 2024-12-06 23:21:37 字数 829 浏览 0 评论 0原文

当我在 Eclipse 中创建一个新项目时,就会立即发生这种情况。

我的项目中只有 1 个 jar 文件,我尝试删除它,然后再次添加它,多次,然后清理项目。

我已经更新了 ProGuard(我认为),下载了新版本,并按照此处的线程所述替换了 lib 文件夹。

我的 default.properties 文件如下所示:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-8

因此无法评论有关另一个线程中也提到的 ProGuard 的任何内容。 我感觉我已经尝试了一切,但仍然是这个错误。 如果我去,我注意到一件事: 窗口 ->偏好->安卓->构建。并取消选中“当外部 jar 包含本机库时强制出现错误”。然后我得到:“无法解析 R” 而不是 Dalvik 错误。

也没有名为 android.R 的导入。

请有人帮忙吗?

This happens instantly when I make a new project in Eclipse.

I only have 1 jar file in the project, I have tried to remove it, and add it again, several times, and cleaned the project after this.

I have updated ProGuard (I think), downloaded the new version, and replaced the lib folder as the threads on here said.

My default.properties file looks like this:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-8

So can't comment anything about ProGuard which was also mentioned in another thread.
I feel I have tried everything, and still this bug.
One thing I have noticed though if I go to:
window -> preferences -> android -> build. And uncheck "Force error when external jars contain native libraries". Then I get: "Can't resolve R" instead of the Dalvik error.

There is no import named android.R either.

Anyone with some help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

趁年轻赶紧闹 2024-12-13 23:21:37

这看起来不像是 proguard 的问题,因为它甚至没有在您的 defaults.properties 文件中启用。尝试以下操作:

  1. 取消选中“当外部 jar 包含本机库时强制出现错误”选项(就像您所做的那样)
  2. 从菜单中选择“项目 -> 清理...”
  3. 如果这无助于确保您导入了正确的 R 类。如 source.android.com 中所述:

    <块引用>

    Eclipse 有时喜欢在
    使用资源的文件的顶部,尤其是当您询问 Eclipse 时
    对进口进行排序或以其他方式管理。这将导致你的 make
    休息。留意这些错误的导入语句并将其删除。

更新

另请查看此线程:“外部 JAR 上转换为 Dalvik 格式失败,错误 1”< /a>.
检查以下答案(链接将直接带您找到答案):

This doesn't look like the issue with proguard, since it's not even enabled in your defaults.properties file. Try the following:

  1. Uncheck "Force error when external jars contain native libraries" option (just as you did)
  2. Select "Project -> Clean…" from the menu
  3. If that won't help ensure you have the correct R class imported. As stated at source.android.com:

    Eclipse sometimes likes to add an import android.R statement at the
    top of your files that use resources, especially when you ask eclipse
    to sort or otherwise manage imports. This will cause your make to
    break. Look out for these erroneous import statements and delete them.

UPDATE

Have a look also at this thread: "Conversion to Dalvik format failed with error 1" on external JAR.
Check the following answers (link will bring you directly to the answer):

阳光下慵懒的猫 2024-12-13 23:21:37

我错误地添加了对 android.jar 副本的引用,这不是必需的,因为它是 android 依赖项,我删除了它,错误消失了。

I had mistakenly added a reference to a copy of android.jar, which was not required as it is an android dependency, I removed this and the error went away.

不弃不离 2024-12-13 23:21:37

我也开始遇到这个问题......唯一为我解决这个问题的是手动下载最新版本的 ProGuard(当前为 4.6)并用最新版本替换 SDK 版本的 Proguard 的 bin 和 lib 文件夹。

之后一切又开始工作了。这显然是一个已记录的错误......
http://code.google.com/p/android/issues/detail ?id=18359

I started having this problem as well... The only thing that fixed it for me was manually downlaoding the newest version of ProGuard (currently 4.6) and replacing the SDK's version of Proguard's bin and lib folders with the newest verison.

After that everything started working again. This is apparently a logged bug...
http://code.google.com/p/android/issues/detail?id=18359

红墙和绿瓦 2024-12-13 23:21:37

你有新的Android SDK吗?如果这样做,您必须从 proguard 网站下载 proguard.jar 并将其替换到 SDK 目录中。

Do you have the new Android SDK? If you do, you have to download the proguard.jar from the proguard website and replace it on the SDK directory.

原来是傀儡 2024-12-13 23:21:37

我自己只是在与这个问题作斗争,最终我所做的是编辑 proguard.bat 文件,问题消失了,

它位于:[Android SDK Installation Directory]\tools\proguard\bin\proguard.bat

Change

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*

调用

%java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9

我尝试了很多其他的东西,但这就是对我有用的。

I just was fighting with this problem myself what I ended up doing is editing the proguard.bat file and the problem vanished

it's in: [Android SDK Installation Directory]\tools\proguard\bin\proguard.bat

Change

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*

to

call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9

I tried tons of other stuff but this is what did it for me.

够钟 2024-12-13 23:21:37

如果使用 CVS 更新,则每次都必须清理项目。

You have to clean your project every time if you use CVS update.

云雾 2024-12-13 23:21:37

我偶尔会遇到这个问题,解决方法是关闭“自动构建”。根据我的经验,当自动构建打开时,Eclipse 在构建 apk 时有时会感到困惑。

I have had this problem occasionally and the fix for me is to switch off 'Build Automatically'. In my experience, Eclipse sometimes gets confused when building apks when automatic building is switched on.

只涨不跌 2024-12-13 23:21:37

如果所有解决方案都不适合您,请尝试执行以下操作:

  1. 停止寻找在线帮助。
  2. 转向你的项目。即使在应用程序运行期间没有报告错误,Dalvik 也可能以错误的方式解释代码中的某些内容。

我有这样的问题。禁用 Proguard 的应用程序的多次运行/构建/导出均成功,并且仅在启用 Proguard 后才出现错误 1。
以下步骤可以帮助您解决问题:

  1. 创建一个新项目。
  2. 为了检测可疑的类,请在每次运行导出签名应用程序工具时开始一一添加您的类。
  3. 通过向该类中一一添加代码块来缩小该类中的搜索范围。

就我而言,错误是由以下原因引起的:

float[][] array1 = null, array2;
for(int i = 0; i < someVal; i++){
    if(array1 == null){
        array1 = new float[row][col];
    }
    else{
        array2 = new float[array1.length][array1[0].length]; // ERROR 1
        // it was assumed that array1 is still null
    }
}

当我将其替换为:

float[][] array1 = new float[1][1], array2;
for(int i = 0; i < someVal; i++){
    if(i == 0){
        array1 = new float[row][col];
    }
    else{
        array2 = new float[array1.length][array1[0].length]; // ERROR 1
        // it was assumed that array1 is still null
    }
}

ERROR 1 消失时。

If none of the solutions work for you try to do the following:

  1. Stop looking for online help.
  2. Turn to your project. It can be something in the code that Dalvik interprets in wrong way even if there are no reported errors during the run of application.

I had such a problem. Multiple runs/builds/exports of application with Proguard disabled were successful and only after enabling Proguard an error 1 appeared.
Following steps can help you to resolve the problem:

  1. Create a new project.
  2. In order to detect the suspicious class, begin adding your classes one by one every time running the export signed application tool.
  3. Narrow the search in that class by adding blocks of code to it also one by one.

In my case the error was caused by:

float[][] array1 = null, array2;
for(int i = 0; i < someVal; i++){
    if(array1 == null){
        array1 = new float[row][col];
    }
    else{
        array2 = new float[array1.length][array1[0].length]; // ERROR 1
        // it was assumed that array1 is still null
    }
}

When I replaced it with:

float[][] array1 = new float[1][1], array2;
for(int i = 0; i < someVal; i++){
    if(i == 0){
        array1 = new float[row][col];
    }
    else{
        array2 = new float[array1.length][array1[0].length]; // ERROR 1
        // it was assumed that array1 is still null
    }
}

the ERROR 1 disappeared.

等风来 2024-12-13 23:21:37

我在 stackoverflow 上尝试了很多解决方案,但没有任何效果。
我只是打开项目文件夹中的 project.properties 文件,并且 appcompat 库在这里添加了两次,如下所示
android.library.reference.1=../appcompat_v7
android.library.reference.1=../appcompat_v7

我刚刚删除了一行,这对我有用:)

I've tried many solutions on stackoverflow but nothing worked for me.
I just open the project.properties file in project folder and appcompat library was added twice here like
android.library.reference.1=../appcompat_v7
android.library.reference.1=../appcompat_v7

I just removed one line and this worked for me :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文