美文网首页
react-native 更改android包名

react-native 更改android包名

作者: xiaotimel | 来源:发表于2020-03-28 17:44 被阅读0次

把原生项目改造成react-native项目
1、直接创建一个空白的的react-native
2、把老的原生项目直接拷贝到相应的文件夹下
3、更改settings.gradle文件

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

直接拷贝到setting.gradle文件
4、在app中添加react native 的依赖

api ("com.facebook.react:react-native:0.60.5"){
        exclude group: 'com.android.support'
    }

自行选择版本
5、在app的build.gradle添加

project.ext.react = [
        entryFile   : "index.tsx",
        enableHermes: false,
]
apply from: "../../node_modules/react-native/react.gradle"


def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);


android {
    compileSdkVersion rootProject.ext.android.compileSdkVersion
    buildToolsVersion rootProject.ext.android.buildToolsVersion

    defaultConfig {
        applicationId "com.you.react.native"
        minSdkVersion rootProject.ext.android.minSdkVersion
        targetSdkVersion rootProject.ext.android.targetSdkVersion
        versionCode rootProject.ext.android.versionCode
        versionName rootProject.ext.android.versionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }

        ndk {
            //设置支持的SO库架构
            abiFilters "armeabi-v7a"
        }
    }

    dexOptions {
        jumboMode = true
        javaMaxHeapSize "4g"
    }

    dataBinding {
        enabled = true
    }
    kapt {
        generateStubs = true
    }
    signingConfigs {

        config {
            storeFile file('../your.jks')
            storePassword "pwd"
            keyAlias "signed_key"
            keyPassword "pwd"
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            minifyEnabled false
            shrinkResources false
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        disable 'MissingTranslation'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    if (enableHermes) {
        def hermesPath = "../../node_modules/hermesvm/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}
repositories {
    mavenCentral()
}

6、新建BUCK文件

# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#

load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")

lib_deps = []

create_aar_targets(glob(["libs/*.aar"]))

create_jar_targets(glob(["libs/*.jar"]))

android_library(
    name = "all-libs",
    exported_deps = lib_deps,
)

android_library(
    name = "app-code",
    srcs = glob([
        "src/main/java/**/*.java",
    ]),
    deps = [
        ":all-libs",
        ":build_config",
        ":res",
    ],
)

android_build_config(
    name = "build_config",
    package = "对应你的包名",
)

android_resource(
    name = "res",
    package = "对应你的包名",
    res = "src/main/res",
)

android_binary(
    name = "app",
    keystore = "//android/keystores:debug",
    manifest = "src/main/AndroidManifest.xml",
    package_type = "debug",
    deps = [
        ":app-code",
    ],
)

原生项目改造成react native项目

相关文章

  • react-native 更改android包名

    把原生项目改造成react-native项目1、直接创建一个空白的的react-native2、把老的原生项目直接...

  • Android更改包名

    原文链接:https://www.jianshu.com/p/8b7412bab029在此只为自己整理方便以后记忆...

  • 如何复制一个APP

    打开Android Studio导入项目 修改包名(在AndroidMainFests.xml文件包名注意更改) ...

  • Android jar包更改包名

    下面介绍如何修改jar文件的包名,需要用到一个小工具,叫做 jarjar.jar 下载地址:http://code...

  • Android jar包更改包名

    1,小工具 jarjar.jar 下载地址:http://code.google.com/p/jarjar/dow...

  • Android更改项目包名

    项目做了一大半,主管说项目包名不好,得改.(可以想象下当时的反应和心情).....没办法只好改.刚开始的包名 第一...

  • Android APP包名更改

    因为客户定制App,需要对copy出来的工程包名进行更改,步骤如下: 1.打开app->src->main->ja...

  • Android 更改包名,屡试不爽

    小菜因为工作需要,经常需要一套代码修改很多次包名,虽然不是什么技术活,但是小菜的用的次数多了就有了一点点小技...

  • 【Flutter】安卓签名和包名

    1、包名 第一步: 更改/android/app/src/main/AndroidManifest.xml文件中的...

  • react-native 修改android包名

    在做微信分享的时候需要用到签名,获取签名的时候需要输入包名,再此修改一下默认的包名com.awesomeproje...

网友评论

      本文标题:react-native 更改android包名

      本文链接:https://www.haomeiwen.com/subject/iejsuhtx.html