2015-05-05 86 views
0

我使用的是Android的科爾多瓦4.0.0它使用gradle這個包裝打造時指定不同的儲存庫。我需要指定與mavenCentral不同的存儲庫。我不能簡單地修改build.gradle文件,因爲它是由Cordova自動生成的。因爲它使用的是Cordova指定的包裝分發,所以我不能在分發中添加/init.d。我試着加入USER_HOME/.gradle/init.gradle文件,它似乎並沒有被習慣。有沒有其他的方式來指定一個初始化文件,當使用我沒有控制權的包裝?使用的gradle科爾多瓦包裝

編輯: 作爲一種解決方法,現在我添加了一個after_prepare掛鉤,它將build.gradle文件中任何位置的文本「mavenCentral()」更改爲我需要使用的存儲庫。我們有了一個更好的基於的Gradle雖然解決方案...

回答

1

我們使用的離子和有我們的,我們用的不是自己的mavenCentral承上啓下庫。我們結束了創建一個鉤加入了鉤來解決這個open issue

module.exports = function(ctx) { 
    'use strict'; 
    var fs = ctx.requireCordovaModule('fs'), 
     path = ctx.requireCordovaModule('path'), 
     deferral = ctx.requireCordovaModule('q').defer(), 
     replaceStream = require('replacestream'), 
     async = require('async'); 
    var platformRoot = path.join(ctx.opts.projectRoot, 'platforms/android'); 
    var gradleFiles = [path.join(platformRoot, 'build.gradle'), path.join(platformRoot, 'CordovaLib', 'build.gradle')]; 
    async.each(gradleFiles, function(f, cb) { 
     fs.readFile(f, 'utf8', function(err, data) { 
      if (err) { 
       cb(err); 
       return; 
      } 
      var result = data.replace(/mavenCentral\(\)/g, 'maven{url "http://nexus.corp.aal.au/content/groups/public-ad"}'); 
      fs.writeFile(f, result, 'utf8', cb); 
     }); 
    }, function(err) { 
     if (err) { 
      deferral.reject(); 
     } else { 
      deferral.resolve(); 
     } 

    }); 
    return deferral.promise; 
} 
0

您指定的gradle這個初始化腳本https://docs.gradle.org/current/userguide/init_scripts.html

像這種額外的Maven的回購協議:

allprojects { repositories { maven { credentials { username 'your_user_name' password 'your_password' } url "https://your_repo" } maven { url "http://download.01.org/crosswalk/releases/crosswalk/android/maven2/" } } }

+0

我的問題解釋說,使用一個init腳本不可的選項(對於init.d)或不工作(init.gradle)。 – SunshinyDoyle

0

這可以工作進行的方式似乎隨着時間而改變。 Cordova/Phonegap的表現讓我很困難。然而,這目前對我的作品:

  • 創建build.gradle文件或複製一個從新制作的Android Studio項目 - 你知道,它喜歡在默認情況下把jcenter()那裏。下面的例子。
  • 它在類型gradleReference添加到您的plugin.xml文件作爲定製的「框架」,在你的Android平臺的標籤。下面的例子。
  • ,而我在它 - 如果你需要其他gradle這個更改,例如Java語言水平,你可以包括build-extras.gradle文件以及來調整其他設置(不知道這些都需要單獨的誠實,但我已經到了我的皮帶的盡頭,試圖處理這件事情)。下面的例子。是的,目標目錄必須是src/..

樣品build.gradle文件:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

dependencies { 
    compile 'net.example:some-sdk:2.3.1' 
} 

樣品plugin.xml

<?xml version="1.0" encoding="UTF-8"?> 
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="io.proxsee" version="0.1.0"> 
    <!-- When you update this file, update the package.json too. --> 
    <!-- Reference: https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html --> 
    <!-- .. other stuff .. --> 
    <platform name="android"> 
     <!-- .. other stuff .. --> 
     <framework src="build.gradle" custom="true" type="gradleReference" /> 
     <source-file src="build-extras.gradle" target-dir="src/.." /> 
    </platform> 
</plugin> 

樣品build-extras.gradle

ext.postBuildExtras = { 
    android { 
     compileOptions { 
      sourceCompatibility JavaVersion.VERSION_1_7 
      targetCompatibility JavaVersion.VERSION_1_7 
     } 
     packagingOptions { 
      exclude 'META-INF/ASL2.0' 
      exclude 'META-INF/LICENSE' 
      exclude 'META-INF/NOTICE' 
      exclude 'META-INF/maven/com.squareup/javawriter/pom.xml' 
      exclude 'META-INF/maven/com.squareup/javawriter/pom.properties' 
     } 
    } 
}