0

Hi,

I have many IONIC project and my job need to remove platform and re-add android platform for those project to build.

Currently i use:

  • IONIC version 1.7.14
  • cordova version 5.4.1

Everything working in old Macpro(with same version ionic/cordova), Problem occur when i move source code to another macbook and reinstall all sdk (ionic/cordova),When i add platform and run: ionic build android --> everytime it need download gradle, stuck this line:

xxx-2:source Vihat$ ionic build android Running command: /Users/macpro/Documents/Developer/TeraPublish/source/hooks/after_prepare/010_add_platform_class.js /Users/macpro/Documents/Developer/TeraPublish/source add to body class: platform-android ANDROID_HOME=/Users/macpro/Library/Android/sdk JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip

i do a lot research and can make it work in single project like this guide: ionic build android error when download gradle

But everytime i create new project or re-add android platform, it still request download gradle. I try to downgrade version of cordova & ionic like my old macbook, but nothing work :(

Can anybody help me solve this case,

Many thanks!.

Community
  • 1
  • 1
QViet
  • 297
  • 5
  • 25

1 Answers1

0

I had a problem with the downloads of gradle, and I fix it with a hook, holding a copy of gradle in my locale, and changing the path of gradlebuild.js to my local

I post my hook:

010_change_build_gradle_path_to_local.js

  #!/usr/bin/env node

//Hook to change the path to the gradle to find the local one, because the proxy  doesn't allow
//to connect to an https server

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

var rootdir = ".",
  androidroot = rootdir + "/platforms/android";

function replace_string_in_file(filename, to_replace, replace_with) {
  var data = fs.readFileSync(filename, 'utf8');

  if(data.indexOf(replace_with) > -1){
    console.log('File already contains required text. Nothing to do.');
  } else {
    console.log(new RegExp(to_replace, "g"));
    var result = data.replace(new RegExp(to_replace, "g"), replace_with);
    fs.writeFileSync(filename, result, 'utf8');
    console.log('Changed Build Gradle Path to local successfully');
  }
}

if(fs.existsSync(androidroot)){
  var targetFile = androidroot + '/cordova/lib/builders/GradleBuilder.js';
  try{
    replace_string_in_file(targetFile, 'http\\\\\\\\://services.gradle.org/distributions/gradle-2.2.1-all.zip', '../../../../../../gradle-2.2.1-all.zip');
  } catch(e){
    console.log("File " + targetFile + " modified successfully");
  }
}

Copy it in before_build folder of hooks, and add gradle-2.2.1-all.zip two levels above your project folder (or modify the hook to match the path).

Víctor
  • 3,029
  • 3
  • 28
  • 43