![](/img/trans.png)
[英]ArthurHub Image cropper not working properly in Fragment, asking for RESULT_OKAY to be defined manually
[英]Image Cropper is not working properly - why?
我正在尝试构建一个 what's app 应用程序,但是当我尝试在build.gradle
实现 android 图像build.gradle
它给了我一些这样的错误
“错误:无法解析 H:\\Project\\WhatsApp2\\app\\src\\main\\AndroidManifest.xml 中的 XML ParseError at [row,col]:[17,9] 消息:预期的开始或结束标记受影响的模块:app”
我的代码如下
Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.whatsapp2">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
tools:replace="android:appComponentFactory"
<activity android:name=".PhoneLoginActivity"></activity>
<activity android:name=".GroupChatActivity" />
<activity android:name=".SettingsActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" />
<activity android:name=".RegisterActivity" />
</application>
</manifest>
构建.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.whatsapp2"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
}
我现在该怎么办?
对于临时解决方案,您可以按如下方式降级版本:
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
代替
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
注意:此错误与可能在库中更新的 android 喷气背包有关。
最近在使用android支持库和第三方库时这个问题变得非常普遍。 尝试迁移到 androidX,它非常安全。 并添加:
android.useAndroidX=true
android.enableJetifier=true
在您的gradle.properties
,如果您使用 android studio 3.2 插件迁移到gradle.properties
,它将自动完成,为此,请转到重构菜单并选择迁移到 androidX。
首先通过重构将你的项目转换成androidx
Refactor-> Migrate to AndroidX -> Migrate
或在gradle.properties
添加以下gradle.properties
行并手动将所有小部件更改为 androidx
android.useAndroidX=true
android.enableJetifier=true
并改变这个
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
进入
api 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
您缺少“>”结束标记,请执行以下操作:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory">
<activity android:name=".PhoneLoginActivity"/>
<activity android:name=".GroupChatActivity" />
<activity android:name=".SettingsActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity" />
<activity android:name=".RegisterActivity" />
</application>
更新:如您所见,您的AndroidManifest.xml
文件中有一个错误,说明:
预期的开始或结束标记 受影响的模块:app
如果您使用以下版本的库
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
然后请将此行添加到您的 Proguard 配置文件( proguard-rules.pro
)并检查一次
-keep class androidx.appcompat.widget.** { *; }
并从<application>
标签之外的清单文件中删除tools:replace="android:appComponentFactory"
对于那些即使在添加依赖项后仍然出现错误的人:
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
如果您的错误可能类似于: CropImage 库的类不是由 IDE 自动建议的,那么您必须确保在您的项目级 build.gradle 文件中包含此maven { url 'https://jitpack.io' }
和jcenter()
。
像这样:
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.google.gms:google-services:4.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
它必须在那种情况下工作。 希望! 它有助于。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.