• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

真 android studio 离线配置

武飞扬头像
hufeng6483
帮助1

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 谷歌 。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/'
        }
        谷歌()  //不要注释
        jcenter() //不要注释
        mavenCentral() // add repository
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
    }
}

allprojects {
    repositories {
        maven{
            url'file:/C:/Users/Administrator/.m2/repository/'
        }
        谷歌()
        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 {
        谷歌()
        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




}


学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgafhkc
系列文章
更多 icon
同类精品
更多 icon
继续加载