最近在做电设,负责声纹识别方向,原本老师要求在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:
Could not resolve all artifacts for configuration ':classpath'
解决完问题2后运行出现上述错误
解决方法: 在build.gradle文件里加上这两句镜像代码,重新编译解决
maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
位置在
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:
Minimum supported Gradle version is 6.5. Current version is 6.1.1.
解决方法: 以下是解决步骤
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的报错代码。
解决方法: 下载对应版本的SDK即可
路径为File → Settings → Appearance & Behavior → System Settings → Android SDK,然后在SDK platform标签下载即可,Android-23对应于API level为23的版本,也就是Android 26
(在这个问题中有可能SDK Platforms无法显示未安装的版本,请转到问题6)
问题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