1.概述
本人經過3天 嘗試操作,試過了6種辦法 閱讀了好多文章 總結出的辦法,
本人使用 大概流程
1.使用gardle 將gardle下載的jar包 轉到本地的maven庫
2.使用本地的maven庫就行
流程很簡單 但是其中遇到的 各種·問題 會讓很多人感到痛苦
下面我來說下具體的流程 遇到的問題
首先是一些問題的說明和講解
①.gardle 檔案
.gardle 檔案 位于 C:/Users/Administrator/.gardle
那么里面包含了什么那 首先我們所使用的 build.tool.gardle.4.1.1會在這里面 ,當你在gardle改變你專案的 否構建版本時 ,就會需要去下載新的版本工具,如果在斷網情況下 就會發生 no cach build.tool.gardle.xxx的問題 這個問題怎么解決 因為你的專案是斷網的 所以你需要用外網電腦去運行專案 然后將運行完后的.gardle 檔案或這個檔案其中的 .gradle\caches\modules-2\files-2.1\com.android.tools.build\builder\ 把builder中的 對應的你所缺失的 版本檔案夾 復制到離線電腦的環境中去
② offline modle
offline modle 在哪 首先隨著android studio的版本更替 新版本的 offline modle 目前在這

當你 是否打開 offline modle 所在專案構建中報的錯是不一樣的· 本人建議直接開啟離線 如果未打開離線模式的話 在專案構建的程序中 缺庫的話 會提示
no google ,com(沒谷歌代理) 打開離線模式后 會直接提示缺那些庫
③ 離線使用 gardle和 gardle的設定界面的詳解

點擊這里直接進入 gardle設定界面 如下圖

這里面 1.代表gardle room 你運行專案時 下載 構建的東西都在這里 有時 很重要 在將專案移動到內網后 這個專案原先的 gardle room 路徑不要變
2.這里代表的·一是很簡單 Specified location 代表使用本地下好的gardle運行,這個下載好的gardle的路徑在3 我的是這樣 :C:\Users\Administrator.gradle\wrapper\dists\gradle-6.5-bin\6nifqtx7604sqp1q6g8wikw7p\gradle-6.5
2中 ‘gradle-wrapper.properties’ file 代表使用 gradle-wrapper.properties 檔案 中的路徑 我使用的是本地的 如下:
distributionUrl=file:///C:/Users/Administrator/.gradle/wrapper/dists/gradle-6.5-bin/6nifqtx7604sqp1q6g8wikw7p/gradle-6.5-bin.zip
④本地倉庫 url’file:/C:/Users/Administrator/.m2/repository/’
本地maven倉庫的路徑在上面所示 的路徑 我們之后讀取的庫 都在這里
具體流程
1.首先在外網電腦 成功構建運行專案 讓gardle 將所需要下載的庫都下載好
2.在外網電腦的 build.gardle(Project)里面新增 task 代碼如下
在這里插入代碼片
task cacheToLocalMavenRepository(type: Copy) {
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1')
into repositories.mavenLocal().url
eachFile {
List<String> parts = it.path.split('/')
it.path = (parts[0]+ '/' + parts[1]).replace('.','/') + '/' + parts[2] + '/' + parts[4]
}
includeEmptyDirs false
}
``然后在 `terminal 欄里進行 gardle庫轉移到本地maven操作
具體參開這個文章
https://blog.csdn.net/u012551120/article/details/116047944?utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-14.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-14.control
3.將外網電腦的
.gardle .android .m2 檔案夾 和sdk 全部復制(也許只需要替換.gardle和 .m2 ) 替換到 內網電腦上
4.打開內網 android studio 進行 專案構建
構建失敗 可回頭看看 ①.gardle 檔案 中所講的問題
5 最重要的一點 如果 提示 no cache xxxxx 導致構建失敗 切記 先去 .m2/repository 去追找 可能 m2中沒有這個庫 有的話 可能是 還未重繪
(重要) 只要在builld.gardle(moudle)中的 dependencies { } implementation 后 再進行 Invalidate and Restart 就可以了(多試幾次 我的及時 一個庫 反復了幾回才可以的 我就感覺肯定是gardle的構建流程的,pom檔案未重繪所導致的,大家有不同見解可以留言 大家相互討論 共同進步)
6.最最重要一步 buildgardle的代碼 大家 修改 repositories {} 里面的跟我一樣就行 但是 路徑大家得看清楚每個人的用戶名是不一樣的
這個是 build gardle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
//使用本地maven庫
maven{
url'file:/C:/Users/Administrator/.m2/repository/'
}
google() //不要注釋
jcenter() //不要注釋
mavenCentral() // add repository
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
}
}
allprojects {
repositories {
maven{
url'file:/C:/Users/Administrator/.m2/repository/'
}
google()
jcenter()
mavenCentral() // add repository
maven { url 'https://jitpack.io' }
}
}
task cacheToLocalMavenRepository(type: Copy) {
from new File(gradle.gradleUserHomeDir, 'caches/modules-2/files-2.1')
into repositories.mavenLocal().url
eachFile {
List<String> parts = it.path.split('/')
it.path = (parts[0]+ '/' + parts[1]).replace('.','/') + '/' + parts[2] + '/' + parts[4]
}
includeEmptyDirs false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build gardle (miudle)
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 28 //26
buildToolsVersion "26.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "xxxxxxxxxx"
minSdkVersion 21
targetSdkVersion 26 //26
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-frtti"
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// android{
// useLibrary 'org.apache.http.legacy'//為了使用過時的HttpClient
// }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// useLibrary 'org.apache.http.legacy'//為了使用過時的HttpClient
}
buildscript {
repositories {
google()
jcenter()
mavenCentral() // add repository
maven { //使用hellochart
url "https://jitpack.io"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // add plugin
}
}
greendao {
schemaVersion 112//更新資料庫版本號
daoPackage 'com.zsch.forestinventory.db.gen'
targetGenDir 'src/main/java'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.drawerlayout:drawerlayout:1.0.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation project(':androidlib')
ttpcomponents/httpclient
implementation group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
implementation 'com.github.lzyzsd.randomcolor:library:1.0.0'
// https://mvnrepository.com/artifact/org.locationtech.jts/jts-core
implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.16.1'
// //引入 jackjson功能
// implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: jacksonVersion
// implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion
// implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: jacksonVersion
// // 引入XML功能
// implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: jacksonVersion
// // 比JDK自帶XML實作更高效的類別庫
// implementation group: 'com.fasterxml.woodstox', name: 'woodstox-core', version: '5.1.0'
// compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.22'
//引入 WilliamChart
// implementation 'com.diogobernardino:williamchart:3.7.1'
// implementation 'com.diogobernardino.williamchart:tooltip-slider:3.7.1'
// implementation 'com.diogobernardino.williamchart:tooltip-points:3.7.1'
//為了使用MultipartEntityBuilder
// compileOnly group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.12'
compileOnly group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.12'
// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore
compileOnly group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.13'
// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/294250.html
標籤:其他
上一篇:Activity的啟動流程
下一篇:解決Android Handler的handleMessage()方法內TextView.setText偶爾不執行的問題
