【奇技淫巧】AndroidStudio Nexus3.x搭建Maven私服遇到問題及解決方案

以前寫過 Android Studio 多個項目依賴同一個模塊的用法
不過在使用中遇到了幾個問題,編譯速度慢,老是顯示出關聯項目。
因此決定將公共模塊aar使用 maven 私服管理,在此記錄之。css

Nexus3 下載與安裝

官網
下載後解壓,這裏以windows爲例
打開 D:\nexus-3.20.1-01-win64\nexus-3.20.1-01\bin 目錄
在該目錄下執行html

nexus.exe /run
複製代碼

見到 Started Sonatype Nexus OSS 3.20.1-01 字樣即成功
打開 http://localhost:8081/ 進入配置界面java

詳情參考 Maven私服Nexus 3.x搭建android

網上文章不少,下面說一下搭建過程當中出現的問題。git

問題及解決方案

1 unable to resolve dependency for:xxx

正常配置並引入私服的依賴,可是提示沒法resolve該依賴github

解決windows

1. Nexus 容許匿名登陸bash

勾選容許匿名登陸

這種操做很暴力app

2. 引用依賴配置帳號密碼jvm

project 的 build.gradle allprojects->repositories中配置maven url 的同時配置用戶名密碼

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            credentials {
                username 'username'
                password 'password'
            }
            url 'http://localhost:8081/repository/Android/'
        }
    }
}
複製代碼

2 aar中的class.jar爲空

成功引入依賴後發現找不到aar中的類

詳情參考 解決aar混淆後包裏是空的問題,android混淆講解

解決

打出的aar是release的,因此關閉release的混淆,或者想暴露出的類禁止混淆便可

3 錯誤: 編碼GBK的不可映射字符

生成 java doc 時提示錯誤: 編碼GBK的不可映射字符

在module的build.gradle中配置

tasks.withType(Javadoc) {
    options.addStringOption('Xdoclint:none', '-quiet')
    options.addStringOption('encoding', 'UTF-8')
}
複製代碼

4 javadoc: 錯誤 - 非法的程序包名稱

在 Root Project 下的 build.gradle 文件中 buildscript 下的 dependencies 中添加:

classpath 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.17'
複製代碼

module 的 build.gradle 應用插件

apply plugin: 'org.jetbrains.dokka-android'
複製代碼

詳情參考 使用Gradle打包Kotlin項目代碼、生成Kotlin代碼文檔

5 deploy 時出現 500, ReasonPhrase: Internal Privoxy Error.

> Failed to deploy artifacts: Could not transfer artifact 
cn.example.baselib:library-base:aar:0.0.1 
from/to remote (http://localhost:8081/repository/Android/): 

Failed to transfer file:
http://localhost:8081/repository/Android/cn/example/baselib/library-base/0.0.1/library-base-0.0.1.aar. 
Return code is: 500, ReasonPhrase: Internal Privoxy Error.
複製代碼

解決: 關閉Android Studio代理

windows在C:\Users\Administrator\.gradle\gradle.properties文件

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Mon Jan 06 13:56:29 CST 2020
移除代理
#systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=1080
複製代碼

感謝

Android Studio將項目發佈到Maven倉庫(3種方式最新最全)

Kotlin與Java混編項目的Nexus私有倉庫持續交付與集成

Maven私服Nexus 3.x搭建

解決aar混淆後包裏是空的問題,android混淆講解

使用Gradle打包Kotlin項目代碼、生成Kotlin代碼文檔

雕蟲曉技(四) 搭建私有Maven倉庫(帶容災備份)


關於我


我是 Fly_with24

相關文章
相關標籤/搜索