目前分類:Android-菜鳥筆記 (5)

瀏覽方式: 標題列表 簡短摘要

前陣子在研究Android TV的開發,使用的TV BOX是小米盒子三增強版/小米盒子國際版/小米盒子S(國際版)

因為第一個是小米UI,跟國際版操作不太一樣,所以特別筆記一下免得忘記了...

一、開啟開法者模式

1.在小米盒子設置中選關於

小米盒子

2.對產品型號多次點擊,直到出現"您已處於開發者模式,無需進行此操作",完成開啟開發者模式

小米盒子

 

二、開啟ADB調試-可連接USB安裝apk進行測試

1.一樣進入小米盒子設置後,選擇帳號與安全

小米盒子

2.開啟ADB調試

小米盒子

 3.插上USB線後跳出,是否允許USB調試的對話框,選擇確定即完成

小米盒子

 

文章標籤

muchone 發表在 痞客邦 留言(0) 人氣()

● 要將android studio的專案打包成sdk,分為兩種,.jar和.aar,差別在於

jar(Java Archive):是 Java 的一種檔案格式,包含class檔案與text檔案 ,不包含res中的檔案。

aar(Android Archive):除了上述的class檔案與text等檔案,還包含所有res中的檔案。

所以如果要打包的sdk只有使用class,那就直接打包jar檔案即可,但如果是有包含UI(res資源)的sdk,就要打包成aar檔案

 

●作法:

 1.開啟要打包的專案,將build.gradle(app)中的

apply plugin: 'com.android.application' 改為 apply plugin: 'com.android.library'

applicationId "your application id"註解掉

 

sdk1.png

 

2.上述步驟完成後sync,再rebuild project

sdk2.png

 

3.這時會產生兩個檔案,

jar檔:在app/build/intermediates/packaged-classes/debug下會有一個classes.jar

sdk3.png

aar檔:在app/build/outputs/aar下會有一個app-debug.aar檔

這樣就完成了SDK的打包囉!!

sdk4.png

 

*測試:另外開啟一個專案來測試剛剛打包的SDK是否可以正常的匯入新專案

匯入一樣分為兩種

(一)aar的匯入:

1.將打包好的aar檔放到新開專案中的app/libs下

sdk5.png

2.在build.gradle(project)中的repositories下增加

flatDir {

    dirs 'libs'

}

sdk6.png

3.到build.gradle(app) 新增 dependency:

implementation (name:'stroke', ext:'aar')

 

(二)jar檔,

1.將打包好的jar檔放到新開專案中的app/libs下

2.到build.gradle(app) 新增 dependency:

implementation fileTree(include: ['*.jar'], dir: 'libs')

sdk7.png

 

完成後測試StrokeTextView這個sdk是否可以正常使用,加入如下xml

(因為這邊打包的sdk有包含UI所以是採用AAR檔的方式)

sdk8.png

測試完成畫面!!成功!!

sdk9.png

文章標籤

muchone 發表在 痞客邦 留言(0) 人氣()

1.開啟新的專案,選擇Empty Activity

android 建立 library

 

2.設定專案名稱與位置

android 建立 library

3.專案開啟後,選擇File=>New Module 建立一個新的Module

android 建立 library

4.選擇Android Library=>Finish

android 建立 library

5.設定library name

android 建立 library

 

6.設定完,專案就會出現剛剛建立的library

android 建立 library

 

7.進到library的目錄下,新建一個空的Class

android 建立 library

 

8.在class中寫入要做為library的內容,本例中實際使用的程式內容比較多,這邊不列出

9.完成後將程式上傳至自己的github中

10.上傳後,在新建的repository中選Release=>Create a new release

android 建立 library

11.在上方欄位輸入版本號,下方為標題=>按下Publish

android 建立 library

 

12.發布完成後顯示如下畫面

android 建立 library

13.到JitPack.io 在"Look up"欄位輸入github repository 位址(名稱)再按下"Look up"=>下方會顯示剛才在github release 設定的版本號,按下"Get it"

android 建立 library

 

14.下方會出現如下畫面,把兩個gradle設定好就可以把這個library 用在別的專案

android 建立 library

 

**補充說明

1.另外開啟一個專案來測試剛剛建立的library可不可以gradle,在build.gradle加入剛剛的implementation,就可以了!

android 建立 library

 

2.在原本的library中也會有一個app資料夾,可以把要做sample或demo的程式放在這,使用本身的library,只要在app的build.gradle加入implementation project(':library名稱')

android 建立 library

 

*Github程式參考:StrokeTextView

*參考資料:How to create your own Android Library and publish it by Anuj Gupta

 

文章標籤

muchone 發表在 痞客邦 留言(1) 人氣()

1.專案顯示方式選擇Anrdoid後,點"show option menu",將Compact Middle Packages勾選取消,此選項勾選時,畫面如左邊,無法層級顯示檔案

android studio rename package

 
2.取消勾選以後,就可以層級顯示package

android studio rename package

 

3.對要修改的package name按右鍵=>Refactor=>Rename

android studio rename package

 

4.選擇Rename package

android studio rename package

 

5.輸入要修改的package name=>Refactor

android studio rename package

 

6.下方會出現preview畫面=>Do Refactor

android studio rename package

7.改好package name,要去build.gradle(Module:app)改applicationId

android studio rename package

8.在values/strings.xml 可以同時把app 顯示的名稱一併改掉

Snap9.png

 

●補充說名--關於packgage name
當開啟新專案時,會要求輸入公司網址,是因為現在都是用公司網址+專案名稱來產生package name,如果沒有網址就隨便打,只要不要重複就好,因為重複的話會無法在google play上架,因為android辨別app差異的方法就是靠package name

 

文章標籤

muchone 發表在 痞客邦 留言(0) 人氣()

●方法一
跳出更新推薦的時候,點更新,會全部自動設定好
android studio版本更新報錯處理
 
●方法二:如果沒有自動跳出更新,build的時候會出現很多錯誤訊息,照說明一個一個更改即可
1.build.gradle(project)=>tools.build 3.0.1改為3.4.0
android studio版本更新報錯處理
 
2.gradle-wrapper.properties=>gradle-4.1-all.zip改為gradle-5.1.1-all.zip
 
3. 可能會出現警告訊息如下:
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018.
WARNING: Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation'.
WARNING: Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018.
 
做法:build.gradle(app)=>compile 改為 implementation、testCompile改為testImplementation、androidTestCompile改為androidTestImplementation (Warning Only)
 
android studio版本更新報錯處理
 
4. 可能會出現警告訊息如下:
WARNING: The specified Android SDK Build Tools version (26.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.0.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '26.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
 
做法:build.gradle(app)=>buidlToolsVersion 26.0.2改為28.0.3(android studio  minimum supported version (28.0.3) for Android Gradle Plugin 3.4.0. )
 
android studio版本更新報錯處理
 
 
5.如果出現如下列訊息:
ERROR: Could not find com.android.tools.build:gradle:3.0.1.
Searched in the following locations:
Required by:
    project :
Add Google Maven repository and sync project
Open File
 
ERROR: Failed to resolve: com.android.support:appcompat-v7:26.+
Add Google Maven repository and sync project
Show in Project Structure dialog
Affected Modules: app
 
 
ERROR: Failed to resolve: com.android.support.constraint:constraint-layout:1.0.2
Install artifact and sync project
Show in Project Structure dialog
Affected Modules: app
 
 
ERROR: Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
Add Google Maven repository and sync project
Show in Project Structure dialog
Affected Modules: app
 
=>點"Add Google Maven repository and sync project",出現如下畫面,點擊"Do refactor"即可
擷取.PNG

 

 

*使用openCV遇到的錯誤訊息
ERROR: The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
WARNING: The targetSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
 
作法:在openCVLibrary343的AndroidManifest.xml,移除minSdk和targetSdk設定
android studio版本更新報錯處理
 
另外:openCVLibrary343Library的build.gradle(app)的buidlToolsVersion也要改為28.0.3(改法同方法2)
 
 
*使用firebase Message 會crash
Default FirebaseApp is not initialized in this process com.maggie.faceaimessage. Make sure to call FirebaseApp.initializeApp(Context) first.
 
做法:build.gradle(project)將classpath改為 'com.google.gms:google-services:4.2.0'
android studio版本更新報錯處理
 

Android Studio 各版本下載:https://developer.android.com/studio/archive

文章標籤

muchone 發表在 痞客邦 留言(0) 人氣()