天天看點

AndroidStudio跑科大訊飛聲紋識别demo 問題彙總

最近在做電設,負責聲紋識别方向,原本老師要求在STM32上實作聲紋識别功能,找遍網上都沒有代碼,打算先用AndroidStudio跑一下科大訊飛的聲紋識别demo找找感覺。

第一次用AS,再加上科大訊飛的這個demo好像不太完整(少了一個build.gradle檔案),導緻出現了很多報錯,在這裡彙總一下。

問題1: 官網下的“将在官網下載下傳的Android SDK 壓縮包中libs目錄下所有子檔案拷貝至Android工程的libs目錄下。”這句是相對于Eclipse環境說的。

解決方法: AS環境下需要将.jar檔案拷貝至 “工程名\app\libs”目錄下,将.so檔案拷貝至 “工程名\app\ src\main\jniLibs”目錄下(沒有的自己建立)。

問題2:

Plugin with id 'com.android.application' not found
           

這是由于build.gradle少了幾行代碼

解決方法: 在build.gradle中添加

buildscript {
    repositories {
        google()
        jcenter()
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
}
           

問題3:

解決完問題2後運作出現上述錯誤

解決方法: 在build.gradle檔案裡加上這兩句鏡像代碼,重新編譯解決

位置在

buildscript {
    repositories {
        google()
        jcenter()
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
}
           

問題4:

解決方法: 以下是解決步驟

1首先通過Help→About檢視目前AS版本,我的為4.1.2

2檢視build.gradle,找到

buildscript {
    repositories {
        google()
        jcenter()
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
           

其中classpath "com.android.tools.build:gradle:4.1.2"寫的版本要和第一步查找到的版本一樣

3由于這個demo缺失gradle檔案夾,建立一個工程把gradle複制過來就可以了。

問題5: Gradle sync failed: com.android.tools.idea.gradle.project.sync.idea.issues.SdkPlatformNotFoundException: Module: ‘speechDemo’ platform ‘android-23’ not found.

問題4解決完後出現問題5,在網上搜尋發現是SDK platform缺少對應版本android-23導緻的。

關于問題5這段代碼的出現,我首先在下圖中的最底部發現有錯誤(failed),點選後自動彈出右下角的event log視窗,在這個視窗中發現問題5的報錯代碼。

AndroidStudio跑科大訊飛聲紋識别demo 問題彙總

解決方法: 下載下傳對應版本的SDK即可

路徑為File → Settings → Appearance & Behavior → System Settings → Android SDK,然後在SDK platform标簽下載下傳即可,Android-23對應于API level為23的版本,也就是Android 26

(在這個問題中有可能SDK Platforms無法顯示未安裝的版本,請轉到問題6)

AndroidStudio跑科大訊飛聲紋識别demo 問題彙總

問題6: 下載下傳Android SDK時SDK Platforms隻能顯示已下載下傳的版本,未下載下傳的版本無法顯示。

出現這個問題是被牆了,我在網上發現兩種方法,其中一種設定HTTP Proxy已經沒用了,另一種方法是修改hosts檔案,在Android Studio中下載下傳Android SDK的兩種方式(Android Studio3.0、windows)這裡已經講得很清楚。

解決方法:

1進入網站http://ping.chinaz.com/,進行 dl.google.com ping檢查,選擇大陸響應時間最短的IP位址

2進入cmd對此IP位址進行ping測試(指令為ping IP位址),如果可以使用就将(IP位址 dl.google.com)加入hosts檔案中

hosts檔案的路徑為C:\WINDOWS\System32\drivers\etc\hosts,用記事本打開

并在最後添加

127.0.0.1 localhost
IP位址 dl.google.com
           

如果沒有生效,在cmd視窗中輸入

ipconfig /flushdns
           

就會發現platform中SDK的版本都出現啦

問題7: Failed to find Build Tools revision xx.x.x

解決方法: 建立一個工程,檢視build.gradle檔案的compileSdkVersion、buildToolsVersion、targetSdkVersion版本并改到demo的build.gradle中。

問題8: build.gradle檔案中出現紅色的錯誤,且compile被劃線

解決方法: android新版本推薦用implementation代替compile。

最後,發現在github上有别人寫好的現成能跑的代碼,就不用繼續弄這個SDK了。前前後後浪費了我将近一周的時間。

github代碼:https://github.com/Unixtrong/SpeechDemo