简体   繁体   English

更改Cordova Eclipse项目中的应用程序图标

[英]Change icon of application in Cordova eclipse project

I'm trying to change the icon of the aplication I'm building with Cordova through Eclipse. 我正在尝试通过Eclipse更改与Cordova一起构建的应用程序的图标。

I've tried 2 different methods, which both failed. 我尝试了2种不同的方法,但都失败了。 I first tried to add the following kind of lines to my projroot/www/config.xml: 我首先尝试将以下几行添加到我的projroot / www / config.xml中:

<icon src="icon.png" alsoAddedOtherParameters />

Which results in: 结果是:

 [aapt] C:\Program Files (x86)\eclipse\configuration\org.eclipse.osgi\920\data\proj_gen\csam.test\android\bin\AndroidManifest.xml:26: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/icon').

BUILD FAILED
C:\Users\Pieter\AppData\Local\Android\android-sdk\tools\ant\build.xml:649: The following error occurred while executing this line:
C:\Users\Pieter\AppData\Local\Android\android-sdk\tools\ant\build.xml:694: null returned: 1

I also found a second approach through hooks. 我还通过钩子找到了第二种方法。 But this just didn't change anything. 但这并没有改变任何东西。 Below is a screenshot of my filestructure and below you can find the hook script. 下面是我的文件结构的屏幕截图,下面是钩子脚本。 Maybe the hook script doesn't get executed when building through eclipse? 通过Eclipse构建时,钩子脚本可能未执行?

#!/usr/bin/env node

//
// This hook copies various resource files 
// from our version control system directories 
// into the appropriate platform specific location
//


// configure all the files to copy.  
// Key of object is the source file, 
// value is the destination location.  
// It's fine to put all platforms' icons 
// and splash screen files here, even if 
// we don't build for all platforms 
// on each developer's box.

var filestocopy = [{
    "config/android/res/drawable/icon.png": 
    "platforms/android/res/drawable/icon.png"
}, {
    "config/android/res/drawable-hdpi/icon.png": 
    "platforms/android/res/drawable-hdpi/icon.png"
}, {
    "config/android/res/drawable-mdpi/icon.png": 
    "platforms/android/res/drawable-mdpi/icon.png"
}, {
    "config/android/res/drawable-xhdpi/icon.png": 
    "platforms/android/res/drawable-xhdpi/icon.png"
}, ];

var fs = require('fs');
var path = require('path');

// no need to configure below
var rootdir = process.argv[2];

filestocopy.forEach(function(obj) {
    Object.keys(obj).forEach(function(key) {
        var val = obj[key];
        var srcfile = path.join(rootdir, key);
        var destfile = path.join(rootdir, val);
        //console.log("copying "+srcfile+" to "+destfile);
        var destdir = path.dirname(destfile);
        if (fs.existsSync(srcfile) &amp;&amp; fs.existsSync(destdir)) {
            fs.createReadStream(srcfile).pipe(
               fs.createWriteStream(destfile));
        }
    });
});

在此处输入图片说明

You have to configure your AndroidManifest.xml file to make it point to your icon : 您必须配置AndroidManifest.xml文件使其指向您的图标:

<application android:hardwareAccelerated=”true” android:icon=”@drawable/myIcon” android:label=”@string/app_name”>

Command line compilation : 命令行编译:

Open cmd

cd yourproject

cordova platforms add android

You will get a folder and go to and make the modification with the line I told you first. 您将得到一个文件夹,然后转到我首先告诉您的那一行进行修改。

/android/platforms/AndroidManifest.xml

Finally 最后

cordova run android

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM