由于找不到符号 picasso.fit(),无法构建 apk;

Unable to build apk due to cannot find symbol picasso.fit();

我正在尝试使用 cordova build android 命令构建 APK,但在构建过程中发生错误并且无法生成构建。错误与 PICASSO 库有关。请在下面找到所有相关详细信息。 离子信息:

 Ionic:
 ionic (Ionic CLI) : 4.8.0 (/usr/lib/node_modules/ionic)
 Ionic Framework   : ionic1 1.3.1
 @ionic/v1-toolkit : not installed
 Cordova:
 cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
 Cordova Platforms     : android 6.4.0
 Cordova Plugins       : cordova-plugin-ionic-webview 1.2.1, (and 19 
 other plugins)

 System:

 Android SDK Tools : 26.1.1 (/home/user/Android/Sdk)
 NodeJS            : v8.11.3 (/usr/bin/node)
 npm               : 5.6.0
 OS                : Linux 4.15

platforms/android/com-sarriaroman-photoviewer/abc123photoviewer.gradle 有以下代码

repositories{
jcenter()
}
dependencies {
implementaion 'com.commit451:PhotoView:1.2.4'
implementaion 'com.squareup.picasso:picasso:2.5.2'
}
android {

}

因此出现错误

    BUILD FAILED in 3s
38 actionable tasks: 36 executed, 2 up-to-date
/var/www/projects/ionic_practice/test/app_mobile_new/platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/var/www/projects/ionic_practice/test/app_mobile_new/platforms/android/src/com/sarriaroman/PhotoViewer/PhotoActivity.java:171: error: cannot find symbol
            picasso.fit();
                   ^
  symbol:   method fit()
  location: variable picasso of type Picasso
/var/www/projects/ionic_practice/test/app_mobile_new/platforms/android/src/com/sarriaroman/PhotoViewer/PhotoActivity.java:175: error: cannot find symbol
            picasso.centerInside();
                   ^
  symbol:   method centerInside()
  location: variable picasso of type Picasso
/var/www/projects/ionic_practice/test/app_mobile_new/platforms/android/src/com/sarriaroman/PhotoViewer/PhotoActivity.java:179: error: cannot find symbol
            picasso.centerCrop();
                   ^
  symbol:   method centerCrop()
  location: variable picasso of type Picasso
/var/www/projects/ionic_practice/test/app_mobile_new/platforms/android/src/com/sarriaroman/PhotoViewer/PhotoActivity.java:200: error: cannot find symbol
                    .into(photo, new com.squareup.picasso.Callback() {
                    ^
  symbol:   method into(ImageView,<anonymous Callback>)
  location: class Picasso
/var/www/projects/ionic_practice/test/app_mobile_new/platforms/android/src/com/sarriaroman/PhotoViewer/PhotoActivity.java:224: error: cannot find symbol
                    Piccasso picasso = Picasso.with(PhotoActivity.this)
                    ^
  symbol: class Piccasso
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
5 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

这是插件 1.20 版的问题。

您可以使用 1.1.18,它与它配合得很好。

这是移动到 1.1.18 的方法

$ ionic cordova plugin rm com-sarriaroman-photoviewer
$ ionic cordova plugin add com-sarriaroman-photoviewer@1.1.18

构建并运行

cordova build android 

...
...
...
:app:transformResourcesWithMergeJavaResForDebug
:app:packageDebug
:app:assembleDebug
:app:cdvBuildDebug

BUILD SUCCESSFUL in 32s
46 actionable tasks: 46 executed

如果仍然出现与之前相同的错误,请尝试删除 android 平台并再次添加,

$ cordova platform rm android

$ cordova platform add android

这是为了确认插件 1.20 版的问题已在最新版本 1.2.4 上得到解决

这是移动到最新的方法

$ ionic cordova plugin rm com-sarriaroman-photoviewer
$ ionic cordova plugin add com-sarriaroman-photoviewer

版本 1.2.5 解决了这个问题

ionic cordova plugin rm com-sarriaroman-photoviewer
ionic cordova plugin add com-sarriaroman-photoviewer