我在android平台上构建离子项目时遇到错误:
ionic cordova build android
找不到:barcodescanner: 在以下位置搜索: 文件:/Users/user/Library/Android/sdk/extras/m2repository//barcodescanner//barcodescanner-.pom 文件:/Users/user/Library/Android/sdk/extras/m2repository//barcodescanner//barcodescanner-.aar 文件:/Users/user/Library/Android/sdk/extras/google/m2repository//barcodescanner//barcodescanner-.pom 文件:/Users/user/Library/Android/sdk/extras/google/m2repository//barcodescanner//barcodescanner-.aar 文件:/Users/user/Library/Android/sdk/extras/android/m2repository//barcodescanner//barcodescanner-.pom 文件:/Users/user/Library/Android/sdk/extras/android/m2repository//barcodescanner//barcodescanner-.aar https://jcenter.bintray.com//barcodescanner//barcodescanner-.pom https://jcenter.bintray.com//barcodescanner//barcodescanner-.aar https://maven.google.com//barcodescanner//barcodescanner-.pom https://maven.google.com//barcodescanner//barcodescanner-.aar https://repo1.maven.org/maven2//barcodescanner//barcodescanner-.pom https://repo1.maven.org/maven2//barcodescanner//barcodescanner-.aar 文件:/Users/user/developer/project/platforms/android/app/libs/barcodescanner-.aar 文件:/Users/user/developer/project/platforms/android/app/libs/barcodescanner.aar 要求: 项目:app
这是我的离子环境:
cli包:(/ usr / local / lib / node_modules)
@ionic/cli-utils : 1.19.0
ionic (Ionic CLI) : 3.19.0
全球套餐:
cordova (Cordova CLI) : 8.0.0
本地包裹:
@ionic/app-scripts : 3.1.6
Cordova Platforms : android 7.0.0
Ionic Framework : ionic-angular 3.9.2
系统:
Android SDK Tools : 26.1.1
ios-deploy : 1.9.2
ios-sim : 5.0.1
Node : v8.9.3
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b
我创建了新的空白离子项目,并按照以下命令添加了原生barcodescanner插件:
$ ionic cordova plugin add phonegap-plugin-barcodescanner
$ npm install --save @ionic-native/barcode-scanner
Android SDK构建工具已在27.0.3版本中更新
任何人寻求帮助?
答案 0 :(得分:10)
这是由cordova-android 7和插件之间的不兼容引起的。昨天有人reported it和我fixed it。
您必须等到这些更改作为新版本(可能是7.0.2)发布,或者从github url安装插件
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MyAsyncTasck().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public class MyAsyncTasck extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... voids) {
return chkCon();
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
String result = "Your result is " + aBoolean;
}
}
public boolean chkCon() {
try {
URL url = new URL("http://google.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
return code == 200;
} catch (Exception e){
return false;
}
}