一,Could not resolve all files for configuration ':app:releaseCompileClasspath
react-native版本:0.57.1
这个问题原本不是rn版本的问题,原因是0.57.1将Android SDK的版本更新到27了。
先来看下错误日志:
> Task :app:preReleaseBuild FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':app:releaseCompileClasspath'.
> Could not find support-vector-drawable.aar (com.android.support:support-vector-drawable:27.1.1).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-vector-drawable/27.1.1/support-vector-drawable-27.1.1.aar
> Could not find livedata-core.aar (android.arch.lifecycle:livedata-core:1.1.0).
Searched in the following locations:
https://jcenter.bintray.com/android/arch/lifecycle/livedata-core/1.1.0/livedata-core-1.1.0.aar
> Could not find viewmodel.aar (android.arch.lifecycle:viewmodel:1.1.0).
Searched in the following locations:
https://jcenter.bintray.com/android/arch/lifecycle/viewmodel/1.1.0/viewmodel-1.1.0.aar
> Could not find runtime.aar (android.arch.core:runtime:1.1.0).
Searched in the following locations:
https://jcenter.bintray.com/android/arch/core/runtime/1.1.0/runtime-1.1.0.aar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 14s
11 actionable tasks: 1 executed, 10 up-to-date
这个是只有打包apk时才会出现的错误,需要注意两个地方来确定你的错误和我遇到的是同一类错误:
1.":app:releaseCompileClasspath";
2."com.android.support:support-vector-drawable:27.1.1"。
解决方案:
1.修改android/build.gradle中google()方法的位置,见下方代码注释;
2.如果还不行,就升级gradle版本到4.10.1(我使用的版本,不确定别的版本是否可用)。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google() // new
mavenLocal()
jcenter()
maven {url "https://jitpack.io"}
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {url "https://maven.google.com"}
// google() // old
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.10.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
二,常见错误 Could not install the app on the device
1.新clone的项目,运行之后报这个错误

解决办法:
在项目根目录下执行以下命令:
命令:chmod 755 android/gradlew
三,Could not resolve all files for configuration ':classpath'.问题解决
今天,使用Android Studio 3.0.1 打开下载的工程项目,build project时结果报错,如下:
Error:A problem occurred configuring root project 'apptest'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.0.0.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.0.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:unable to find valid certification path to requested target
解决办法为将com.android.tools.build:gradle的版本号和Android studio的版本号一致。
注意:如何查看android studio版本:菜单栏 > Help > About 即可查看
四,react-native run-android Build failed报错(:app:processDebugManifest FAILED)
命令行输入react-native run-android 的时候build失败,如下所示:
:app:processDebugManifest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute [email protected] value=(false) from AndroidManifest.xml:12:7-34
is also present at [AwesomeProject:react-native-splash-screen:unspecified] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:8:5-25:19 to override.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
解决办法:
一、方法一
仔细看上面报错日志可以看到给的建议,“【Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:8:5-25:19 to override.】”
打开上图所示路径下的AndroidMainfest.xml文件,在manifest的属性中添加“ xmlns:tools="http://schemas.android.com/tools"”,如下所示:
- 添加前
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.awesomeproject">
- 添加后:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.awesomeproject">
然后在<application></application>上添加“tools:replace="android:allowBackup"”,如下所示:
- 添加前:
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">其他代码</application>
- 添加后:
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
tools:replace="android:allowBackup"
android:theme="@style/AppTheme">其他代码</application>
二、方法二
同样是在AndroidMainfest.xml中修改,只需要修改<application></application>中的“android:allowBackup="false"”为“android:allowBackup="true"”就好
- 修改前:
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">其他代码</application>
- 修改后:
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:theme="@style/AppTheme">其他代码</application>
五,使用React-native link的背景
并不是所有的 APP 都需要使用全部的原生功能,包含支持全部特性的代码会增大应用的体积。但我们仍然希望能让你简单地根据自己的需求添加需要的特性。
在这种思想下,我们把许多特性都发布成为互不相关的静态库。
大部分的库只需要拖进两个文件就可以使用了,偶尔你还需要几步额外的工作,但不会再有更多的事情要做了。
我们随着 React Native 发布的所有库都在仓库中的Libraries文件夹下。其中有一些是纯 Javascript 代码,你只需要去import它们就可以使用了。另外有一些库基于一些原生代码实现,你必须把这些文件添加到你的应用,否则应用会在你使用这些库的时候产生报错。
2.具体使用React-native link的步骤:
(1).下载某个库到本地
npm install ******
1
(2).链接某个库到项目中
react-native link *****
1
(3).到此就成功的链接到ios和android项目中了
六sdk.dir sdk路径配置
problem occurred configuring project ':app'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment
七,开发项目中的问题
绝对定位元素被键盘顶起
打开android工程,在AndroidManifest.xml中配置如下:
android:windowSoftInputMode=“stateAlwaysHidden|adjustPan”
1
StatusBar 主题污染
componentDidMount() {
this._navListener = this.props.navigation.addListener('didFocus', () => {
StatusBar.setBarStyle('dark-content');
});
}
componentWillUnmount() {
this._navListener.remove();
}
React Native Text截断
显示数字加粗后最后一位无法显示问题,添加
fontFamily: 'System'
使用Button进行路由跳转时报错
这个错误一般只在开启Debug JS Remotely时出现,可以通过使用TouchableOpacity包裹或替换解决
to be continue
八,AndroidStudio SSL peer shut down incorrectly 问题
AndroidStudio 编译时出现如下问题
SSL peer shut down incorrectly
或者某些jar包下载不下来,一般是因为墙的原因导致的。这时候我们就需要配置镜像来解决这个问题。(为了提高jar包的下载速度也可以配置)配置的方法就是在根build.gradle中添加镜像仓库,一般我们选择阿里的
http://maven.aliyun.com/nexus/content/groups/public/
完整的如下所示
buildscript {
repositories {
google()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
google()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}