2014-01-23 29 views
2

从我一直在读的平台文件夹不应该添加到版本控制。然而...... Condova网站上的splashscreen/icon文档声明将图像置于res文件夹中......Android res文件在Cordova中的位置?

那么我应该如何处理?我想使用合并文件夹,但这只是用于www替换。

任何想法都会很棒。 (如果我添加平台文件夹,它会导致下一个人遇到问题,即使我尝试在编译时创建gitignore文件。

回答

3

我能够弄清楚目前看来最好的做法。 。文件这对于其他人也

我创造了我所需要的资源文件夹,然后写了一个定制钩复制文件下面是我从http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/使用一个很好的例子:

#!/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-ldpi/icon.png": 
    "platforms/android/res/drawable-ldpi/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" 
}, { 
    "config/android/res/drawable/splash.png": 
    "platforms/android/res/drawable/splash.png" 
}, { 
    "config/android/res/drawable-hdpi/splash.png": 
    "platforms/android/res/drawable-hdpi/splash.png" 
}, { 
    "config/android/res/drawable-ldpi/splash.png": 
    "platforms/android/res/drawable-ldpi/splash.png" 
}, { 
    "config/android/res/drawable-mdpi/splash.png": 
    "platforms/android/res/drawable-mdpi/splash.png" 
}, { 
    "config/android/res/drawable-xhdpi/splash.png": 
    "platforms/android/res/drawable-xhdpi/splash.png" 
}, { 
    "config/ios/Resources/icons/icon-72.png": 
    "platforms/ios/YourAppName/Resources/icons/icon-72.png" 
}, { 
    "config/ios/Resources/icons/icon.png": 
    "platforms/ios/YourAppName/Resources/icons/icon.png" 
}, { 
    "config/ios/Resources/icons/[email protected]": 
    "platforms/ios/YourAppName/Resources/icons/[email protected]" 
}, { 
    "config/ios/Resources/icons/[email protected]": 
    "platforms/ios/YourAppName/Resources/icons/[email protected]" 
}, { 
    "config/ios/Resources/splash/[email protected]~iphone.png": 
    "platforms/ios/YourAppName/Resources/splash/[email protected]~iphone.png" 
}, { 
    "config/ios/Resources/splash/[email protected]~iphone.png": 
    "platforms/ios/YourAppName/Resources/splash/[email protected]~iphone.png" 
}, { 
    "config/ios/Resources/splash/Default~iphone.png": 
    "platforms/ios/YourAppName/Resources/splash/Default~iphone.png" 
}, { 
    "config/ios/Resources/splash/Default-Portrait~ipad.png": 
    "platforms/ios/YourAppName/Resources/splash/Default-Portrait~ipad.png" 
}, { 
    "config/ios/Resources/splash/[email protected]~ipad.png": 
    "platforms/ios/YourAppName/Resources/splash/[email protected]~ipad.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) && fs.existsSync(destdir)) { 
      fs.createReadStream(srcfile).pipe(
       fs.createWriteStream(destfile)); 
     } 
    }); 
}); 
0

我要注意的是,复制splash文件现在可以通过config.xml正确完成,所有你需要的是本地文件夹该项目的所有图标和飞溅资产的根。但是,如果您的应用程序需要别的东西复制到res文件夹中,那么当前接受的答案是很好的方法。

在我的项目中,项目文件夹的根目录是另一个名为'res'的文件夹。在里面,我有一个android文件夹和一个ios文件夹,以组织我需要的所有资产。

然后,您只需引用这样的文件,cordova就会自动将它们复制到正确的位置。

<platform name="android"> 
     <icon src="res/android/mdpi.png" density="mdpi" /> 
     <icon src="res/android/hdpi.png" density="hdpi" /> 
     <icon src="res/android/xhdpi.png" density="xhdpi" /> 
     <icon src="res/android/xxhdpi.png" density="xxhdpi" /> 

    <!-- 
    XXHDPI 144×144 drawable-xxhdpi 3 480 DPI 8 to 12 pixels 
    XHDPI 96×96 drawable-xhdpi 2 320 DPI 6 to 8 pixels 
    HDPI 72×72 drawable-hdpi 1.5 240 DPI 4 to 6 pixels 
    MDPI 48×48 drawable-mdpi 1 160 DPI 3 to 4 pixels 
    --> 
    <splash src="res/android/screen.hdpi.9.png" density="hdpi"/> 
    <splash src="res/android/screen.mdpi.9.png" density="mdpi"/> 
    <splash src="res/android/screen.xhdpi.9.png" density="xhdpi"/> 
</platform> 

<platform name="ios"> 

    <icon src="res/ios/icon/icon.png" width="57" height="57"/> 
    <icon src="res/ios/icon/[email protected]" width="114" height="114"/> 
    <icon src="res/ios/icon/icon-40.png" width="40" height="40"/> 
    <icon src="res/ios/icon/[email protected]" width="80" height="80"/> 
    <icon src="res/ios/icon/icon-50.png" width="50" height="50"/> 
    <icon src="res/ios/icon/[email protected]" width="100" height="100"/> 
    <icon src="res/ios/icon/[email protected]" width="120" height="120"/> 
    <icon src="res/ios/icon/[email protected]" width="180" height="180"/> 
    <icon src="res/ios/icon/icon-72.png" width="72" height="72"/> 
    <icon src="res/ios/icon/[email protected]" width="144" height="144"/> 
    <icon src="res/ios/icon/icon-76.png" width="76" height="76"/> 
    <icon src="res/ios/icon/[email protected]" width="152" height="152"/> 
    <icon src="res/ios/icon/icon-small.png" width="29" height="29"/> 
    <icon src="res/ios/icon/[email protected]" width="58" height="58"/> 
    <icon src="res/ios/icon/[email protected]" width="87" height="87"/> 

    <splash src="res/ios/splash/Default~iphone.png" width="320" height="480"/> 
    <splash src="res/ios/splash/[email protected]~iphone.png" width="640" height="960"/> 
    <splash src="res/ios/splash/Default-Portrait~ipad.png" width="768" height="1024"/> 
    <splash src="res/ios/splash/[email protected]~ipad.png" width="1536" height="2048"/> 
    <splash src="res/ios/splash/Default-Landscape~ipad.png" width="1024" height="768"/> 
    <splash src="res/ios/splash/[email protected]~ipad.png" width="2048" height="1536"/> 
    <splash src="res/ios/splash/[email protected]~iphone.png" width="640" height="1136"/> 
    <splash src="res/ios/splash/Default-667h.png" width="750" height="1334"/> 
    <splash src="res/ios/splash/Default-736h.png" width="1242" height="2208"/> 
    <splash src="res/ios/splash/Default-Landscape-736h.png" width="2208" height="1242"/> 
</platform>