未找到扩展 CordovaActivity 的 Java 文件。使用“cordova build”时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20266951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No Java files found which extend CordovaActivity. when use "cordova build"
提问by Hyman Zhang
My computer is Windows 8 64bit, i install cordova and android platform for my project, I have created my project by input cordova create hello com.example.hello HelloWorld
and cordova platform add android
but when i run cordova build
, it show below error:
我的电脑是 Windows 8 64 位,我为我的项目安装了cordova 和 android 平台,我通过输入创建了我的项目cordova create hello com.example.hello HelloWorld
,cordova platform add android
但是当我运行时cordova build
,它显示以下错误:
[Error: No Java files found which extend CordovaActivity.]
[Error: No Java files found which extend CordovaActivity.]
i searched the web but didn't find the solution yet, What's the problem?
我在网上搜索,但还没有找到解决方案,这是什么问题?
回答by Michael Schmidt
The .java file with the Activity extending the CordovaActivity must be exactly in com.example.app - as specified in the config.xml's id="com.example.app" tag.
带有扩展 CordovaActivity 的 Activity 的 .java 文件必须完全在 com.example.app 中 - 如 config.xml 的 id="com.example.app" 标记中所指定。
This changed in 3.2.0 - filed a bug report: https://issues.apache.org/jira/browse/CB-5515
这在 3.2.0 中发生了变化 - 提交了错误报告:https: //issues.apache.org/jira/browse/CB-5515
回答by hyperizer
In Eclipse or another editor, go into the .java source file under platforms/android/src/ and make sure the class extends CordovaActivity (it may have previously extended DroidGap instead).
在 Eclipse 或其他编辑器中,进入平台/android/src/ 下的 .java 源文件并确保该类扩展了 CordovaActivity(它可能之前扩展了 DroidGap)。
回答by Cornelius Parkin
Just on a related topic regarding PhoneGap 3.2causing the same error, chances are that you probably messed up the app when configuring and trying to get it running initially
仅在有关导致相同错误的PhoneGap 3.2的相关主题上,您可能在配置和尝试使其最初运行时搞砸了应用程序
What worked for me was to remove the generated android platform files and just run the RUN command again. So from your PhoneGap project's home directory, do the following
对我有用的是删除生成的 android 平台文件,然后再次运行 RUN 命令。因此,从您的 PhoneGap 项目的主目录中,执行以下操作
cd platforms
sudo rm -rf android
cd ..
sudo phonegap local run android --emulator
I am working on a Macbook Pro with OSX version 10.9
我正在使用 OSX 10.9 版的 Macbook Pro
Hope this helps someone!
希望这可以帮助某人!
回答by JDawgg
I had the same issue (albeit on Ubuntu) and tried Hyperizer's answer, which should have worked... but to no effect for me. Note I had the error after upgrading cordova (from 3.0.9 to 3.4.0-0.1.3), and so my generated platforms folders were out of sync with the latest cordova version.
我遇到了同样的问题(尽管在 Ubuntu 上)并尝试了 Hyperizer 的答案,这应该有效......但对我没有影响。注意我在升级cordova(从3.0.9到3.4.0-0.1.3)后出现错误,所以我生成的平台文件夹与最新的cordova版本不同步。
I found the cleanest thing to do (and this worked for me) is to remove your /platforms/android directory (as per cornelius' answer... but my focus is cordova), and then recreate with cordova so you know everything is up to date and inline with the current cordova version.
我发现要做的最干净的事情(这对我有用)是删除你的 /platforms/android 目录(根据cornelius的回答......但我的重点是cordova),然后用cordova重新创建,这样你就知道一切都好了迄今为止并与当前的cordova 版本一致。
cd platforms
rm -rf android
cd ..
cordova platform add android
Your android folder is recreated, and now try building and running again.
您的 android 文件夹已重新创建,现在尝试重新构建并运行。
cordova build android
cordova emulate android
The downside of blowing away and recreating the android platform folder is that you will need to re-apply any customisations you may have made to the android source...(I hadn't had to thankfully) but then you should be able to pull this from your git etc. At least now you are working on a clean and tidy up to date build.
吹走并重新创建 android 平台文件夹的缺点是您需要重新应用您可能对 android 源所做的任何自定义...这来自您的 git 等。至少现在您正在构建一个干净整洁的最新版本。
回答by TechnoTim
This can happen if your id
and android-packageName
in config.xml
do not match.
如果发生这种情况id
,并android-packageName
在config.xml
不匹配。
android-packageName="com.example.app" id="com.example.app"
android-packageName="com.example.app" id="com.example.app"
回答by Sundar Ram
I had the same error when I cloned my repository from another project. I solved it by removing the platforms and adding it again.
当我从另一个项目克隆我的存储库时,我遇到了同样的错误。我通过删除平台并再次添加来解决它。
回答by Bouncing Bit
I stumbled upon a "solution" for anyone who uses a Framework that "hides" the extending of the CordovaActivity, i.e. the MainActivity looks like this:
对于使用“隐藏”CordovaActivity 扩展的框架的任何人,我偶然发现了一个“解决方案”,即 MainActivity 如下所示:
public class MainActivity extends GDCordovaActivity {...}
where GDCordovaActivyis your Framework Activity extending CordovaActivity.
其中GDCordovaActivy是扩展 CordovaActivity 的框架活动。
Simply add a "foo.java" File to the project only containing a comment like this:
只需将“foo.java”文件添加到项目中,仅包含如下注释:
/** extends CordovaActivity */
As the cordova framework parses the file and doesn't recognize the comments you will be able to call cordova android prepare
etc. without any errors.
由于cordova 框架解析文件并且无法识别您将能够调用cordova android prepare
等的注释而不会出现任何错误。
回答by Christian Olatomiwa
All you need to do is remove platform cordova platform rm android and re-add platform by typing cordova platform add android, and the error goes away
您需要做的就是删除平台cordova platform rm android并通过键入cordova platform add android重新添加平台,错误就会消失
回答by Anthony De Smet
I had too many customisations and did not want to recreate the platforms.
我有太多的自定义,不想重新创建平台。
Solved this by changing the widget id
in defaults.xml
to the new package name (I changed the default io.hellocordova
into my own package structure)
通过将widget id
indefaults.xml
更改为新的包名称解决了这个问题(我将默认值更改io.hellocordova
为我自己的包结构)
回答by hiDemo Studio
This error happened when I change the package id name from the config.xml, such as io.cordova..etc to another package name, so I solved it by removing the platform of android and changed version info and package name from config file, and run command android cordova platform add android
当我将 config.xml 中的包 id 名称(例如 io.cordova..etc)更改为另一个包名称时发生此错误,因此我通过删除 android 平台并从配置文件中更改版本信息和包名称来解决它,并运行命令 android cordova platform add android