简体   繁体   English

从另一台具有不同Gradle版本的PC导入Android Studio项目?

[英]Import Android Studio project from another PC with different Gradle versions?

I have an Android studio project that wrote in Android Studio version 1.3.2. 我有一个在Android Studio版本1.3.2中编写的Android工作室项目。 Now in another PC with Android Studio 2.1.2 I want to import or open that project to it. 现在在另一台安装了Android Studio 2.1.2的电脑上,我想导入或打开该项目。 But when I try, and while opening, error occurred with my Gradle version and want from me to download necessary Gradle version. 但是当我尝试打开时,我的Gradle版本出现错误,并希望我下载必要的Gradle版本。

But for my reasons, I don't want to download new data with Android studio. 但出于我的原因,我不想用Android studio下载新数据。 how can I manually transfer old PC Gradle to new one? 如何手动将旧PC Gradle转移到新PC Gradle? or is there simpler way to resolve that? 还是有更简单的方法来解决这个问题?

1.I faced same problem before .Ok you need to copy .java file and .xml layouts strings,colors,dimen,drawble images and others in old project 1.我之前遇到过同样的问题。你需要在旧项目中复制.java文件和.xml布局字符串,颜色,尺寸,绘图图像等

2.And create new android project in your new android studio and paste that file into that project that's it 2.在你的新android工作室中创建新的android项目,并将该文件粘贴到该项目中

NOTE: Copy only required files only 注意:仅复制所需文件

Adding local Gradle to projects would be really helpful 将本地Gradle添加到项目中会非常有帮助

1.Download Gradle http://www.gradle.org/downloads 1.下载Gradle http://www.gradle.org/downloads

2.Install 2.安装

3.Set Gradle home to the install directory like below : 3.将Gradle home设置为安装目录,如下所示: 在此输入图像描述

there is sample project check it : https://github.com/foragerr/SO-35302414-local-gradle-plugin 有示例项目检查它: https//github.com/foragerr/SO-35302414-local-gradle-plugin

Open your app level build.gradle file and change the gradle version accordingly like 打开你的应用程序级build.gradle文件并相应地更改gradle版本

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

allprojects {
    repositories {
        jcenter()
    }
}

so just change your version from 1.3.2 to 2.1.2 所以只需将您的版本从1.3.2更改为2.1.2

Method: 1 方法:1

Try " File -> New -> Import Project " 尝试“ File - > New - > Import Project

or Create new project and copy-paste all project files(Java,XML,Resource) except gradle folder. 或创建新项目并复制粘贴除gradle文件夹之外的所有项目文件(Java,XML,Resource)。

Method :2 方法:2

Or After Import file just change 2.1.2 to 1.3.2 或者在导入文件后只需将2.1.2更改为1.3.2

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

allprojects {
    repositories {
        jcenter()
    }
}

尝试“文件 - >新建 - >导入项目”或只创建新项目,只需复制粘贴除gradle文件夹以外的所有项目文件(复制后在build.gradle中更改gradle版本)

You Need To Check This From Google Android . 你需要从谷歌Android检查这个。

Plugin version  Required Gradle version
1.0.0 - 1.1.3   2.2.1 - 2.3
1.2.0 - 1.3.1   2.2.1 - 2.9
1.5.0   2.2.1 - 2.13
2.0.0 - 2.1.2   2.10 - 2.13
2.1.3+  2.14.1+

So You Cannot Use Old Gradle Build With new Android Studio Version According to Google. 因此,根据谷歌的说法,您无法使用新的Android Studio版本使用旧Gradle构建。

You Can Use the Older Version of Of Android Studio to Make Your Project Work With the Old Gradle System 您可以使用较旧版本的Android Studio使您的项目与旧Gradle系统一起使用

Look in the SDK Manager what is your highest Android SDK Build-tools version, and copy this version number in your project build.gradle file, in the android/buildToolsVersion property The Build Tool Version Propert Should Be Compatible With the Gradle. 在SDK Manager中查看您最高的Android SDK Build-tools版本,并在项目build.gradle文件中复制此版本号,在android / buildToolsVersion属性中,Build Tool Version属性应与Gradle兼容。

2 ways you could choose to give a try, either of them is okay for me: 您可以选择尝试两种方式,其中任何一种都适合我:

1.Copy files and make some configurations: 1.复制文件并进行一些配置:

  • create a new empty Android project, copy only java source files and layout\\drawable\\colors\\dimens etc but Not exclude AndroidManifest.xml files copy into your new project 创建一个新的空Android项目,只复制java源文件和layout \\ drawable \\ colors \\ dimens等但不排除AndroidManifest.xml文件复制到你的新项目
  • override the AndroidManifest.xml's application tag with the content of the old project's( only ) 使用旧项目的内容覆盖AndroidManifest.xml的应用程序标记( 仅限
  • build the new project, you will meet some 'Not Found' errors, modify package names and path of some files until errors disappear 构建新项目,您将遇到一些“未找到”错误,修改包名称和某些文件的路径,直到错误消失
  • done! 完成了!

2.edit some of gradle files: 2.编辑一些gradle文件:

  • modify contents of "/Users/your_name/your_project_directory/gradle/wrapper/gradle-wrapper.properties(path could be different on windows)" , notice distributionUrl="something like https://mirrors.somewhere.net/mirror/gradle/ gradle-xx.xx-all.zip ", xx.xx determines the version of gradle the project used 修改“/Users/your_name/your_project_directory/gradle/wrapper/gradle-wrapper.properties(path可能在windows上不同)”的内容“ ,请注意distributionUrl =”类似于https://mirrors.somewhere.net/mirror/gradle/ gradle-xx.xx-all.zip “, xx.xx确定项目使用的gradle版本
  • modify contents of " /Users/your_name/your_project_directory/build.gradle " and any modules included in your project will have their own build.gradle file, notice the following: 修改“ /Users/your_name/your_project_directory/build.gradle ”的内容,项目中包含的任何模块都有自己的build.gradle文件,请注意以下内容:

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

Then change ' com.android.tools.build:gradle:xx.xx.xx ' which determines the Plugin version to the version corresponding to the version of ' gradle-xx.xx-all.zip ' which determines the Gradle version as @AndroidHacker's post: 然后更改' com.android.tools.build:gradle:xx.xx.xx ',它将插件版本确定为与' gradle-xx.xx-all.zip '版本对应的版本,该版本将Gradle版本确定为@ AndroidHacker的帖子:

Plugin version  Required Gradle version
1.0.0 - 1.1.3   2.2.1 - 2.3
1.2.0 - 1.3.1   2.2.1 - 2.9
1.5.0   2.2.1 - 2.13
2.0.0 - 2.1.2   2.10 - 2.13
2.1.3+  2.14.1+
  • done! 完成了!

first thanks for your answers. 首先感谢您的回答。 but I finally find the solution to solve this issue without download anything and just with a few changes in versions and files. 但我终于找到解决这个问题的解决方案,无需下载任何东西,只需对版本和文件进行一些更改。

1- Open project folder then /gradle/wrapper/gradle-wraper file. 1-打开项目文件夹,然后打开/ gradle / wrapper / gradle-wraper文件。
2- In this txt file, change distributionUrl value to: https\\://services.gradle.org/distributions/gradle-2.10-all.zip 2-在此txt文件中,将distributionUrl值更改为: https\\://services.gradle.org/distributions/gradle-2.10-all.zip
3- Back to Android Studio.In your project's build.gradle file, change classpath to com.android.tools.build:gradle:2.1.2 3-返回Android Studio。在项目的build.gradle文件中,将classpath更改为com.android.tools.build:gradle:2.1.2
4- In your app's build.gradle file, change buildToolsVersion to "23.0.3" 4-在app的build.gradle文件中,将buildToolsVersion更改为"23.0.3"

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

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