Telegram can not compile with different package name

早过忘川 提交于 2021-01-28 05:23:00

问题


I have succeed compile telegram using default package. But when I rename and refactor all the package with my own package name, update jni sub module and create jni .so by following this link https://stackoverflow.com/a/34323758/7531970, use ndk 14b and put all details needed. But I still keep getting this error, please help me

    08-25 23:39:55.027 26920-26959/com.sipo.messenger E/FA: Uploading is not possible. App measurement disabled
08-25 23:39:55.027 26920-26920/com.sipo.messenger D/dalvikvm: DexOpt: couldn't find static field Landroid/os/Build;.SUPPORTED_ABIS
08-25 23:39:55.027 26920-26920/com.sipo.messenger W/dalvikvm: VFY: unable to resolve static field 183 (SUPPORTED_ABIS) in Landroid/os/Build;
08-25 23:39:55.027 26920-26920/com.sipo.messenger D/dalvikvm: VFY: replacing opcode 0x62 at 0x0006
08-25 23:39:55.047 26920-26920/com.sipo.messenger D/dalvikvm: Trying to load lib /data/app-lib/com.sipo.messenger-2/libtmessages.27.so 0x4292cbd0
08-25 23:39:55.247 26920-26920/com.sipo.messenger D/dalvikvm: Added shared lib /data/app-lib/com.sipo.messenger-2/libtmessages.27.so 0x4292cbd0
08-25 23:39:55.257 26920-26920/com.sipo.messenger D/dalvikvm: Trying to load lib /data/data/com.sipo.messenger/files/lib/libtmessages.27loc.so 0x4292cbd0
08-25 23:39:55.347 26920-26920/com.sipo.messenger D/dalvikvm: Added shared lib /data/data/com.sipo.messenger/files/lib/libtmessages.27loc.so 0x4292cbd0
08-25 23:39:55.777 26920-26920/com.sipo.messenger D/dalvikvm: Trying to load lib /data/data/com.sipo.messenger/files/lib/libtmessages.27loc.so 0x4292cbd0
08-25 23:39:55.777 26920-26920/com.sipo.messenger D/dalvikvm: Shared lib '/data/data/com.sipo.messenger/files/lib/libtmessages.27loc.so' already loaded in same CL 0x4292cbd0
08-25 23:39:55.787 26920-26920/com.sipo.messenger W/dalvikvm: No implementation found for native Lcom/sipo/tgnet/ConnectionsManager;.native_setJava:(Z)V
08-25 23:39:55.787 26920-26920/com.sipo.messenger D/AndroidRuntime: Shutting down VM
08-25 23:39:55.787 26920-26920/com.sipo.messenger W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41e8cda0)
08-25 23:39:55.797 26920-26920/com.sipo.messenger E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.sipo.messenger, PID: 26920
                                                                    java.lang.UnsatisfiedLinkError: Native method not found: com.sipo.tgnet.ConnectionsManager.native_setJava:(Z)V
                                                                        at com.sipo.tgnet.ConnectionsManager.native_setJava(Native Method)
                                                                        at com.sipo.messenger.ApplicationLoader.onCreate(ApplicationLoader.java:205)
                                                                        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
                                                                        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4799)
                                                                        at android.app.ActivityThread.access$1600(ActivityThread.java:170)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1377)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:146)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5662)
                                                                        at java.lang.reflect.Method.invokeNative(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:515)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
                                                                        at dalvik.system.NativeStart.main(Native Method)

This is my gradle

 apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

configurations {
    compile.exclude module: 'support-v4'
}

dependencies {
    compile 'com.google.android.gms:play-services-gcm:11.0.2'
    compile 'com.google.android.gms:play-services-maps:11.0.2'
    compile 'com.google.android.gms:play-services-vision:11.0.2'
    compile 'com.google.android.gms:play-services-wallet:11.0.2'
    compile 'com.google.android.gms:play-services-wearable:11.0.2'
    compile 'com.android.support:support-core-ui:25.3.1'
    compile 'com.android.support:support-compat:25.3.1'
    compile 'com.android.support:support-core-utils:25.3.1'
    compile 'com.android.support:support-v13:25.3.1'
    compile 'com.android.support:palette-v7:25.3.1'
    compile 'net.hockeyapp.android:HockeySDK:4.1.3'
    compile 'com.googlecode.mp4parser:isoparser:1.0.6'
    compile 'com.stripe:stripe-android:2.0.2'
}

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

useLibrary 'org.apache.http.legacy'
defaultConfig.applicationId = "com.sipo.messenger"

sourceSets.main.jniLibs.srcDirs = ['./jni/']

externalNativeBuild {
    ndkBuild {
        path "jni/Android.mk"
    }
}

dexOptions {
    jumboMode = true
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

signingConfigs {
    debug {
        storeFile file("config/release.keystore")
        storePassword 'xxx'
        keyAlias 'release'
        keyPassword 'xxx'
        v2SigningEnabled false
    }

    release {
        storeFile file("config/release.keystore")
        storePassword 'xxx'
        keyAlias 'release'
        keyPassword 'xxx'
        v2SigningEnabled false
    }
}

buildTypes {
    debug {
        debuggable true
        jniDebuggable true
        //signingConfig signingConfigs.debug
        //applicationIdSuffix ".beta"
    }

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

    foss {
        debuggable false
        jniDebuggable false
        signingConfig signingConfigs.release
    }
}

defaultConfig.versionCode = 1043

sourceSets.debug {
    manifest.srcFile 'config/debug/AndroidManifest.xml'
}

sourceSets.release {
    manifest.srcFile 'config/release/AndroidManifest.xml'
}

sourceSets.foss {
    manifest.srcFile 'config/foss/AndroidManifest.xml'
}

productFlavors {
    x86 {
        ndk {
            abiFilter "x86"
        }
        versionCode = 2
    }
    armv7 {
        ndk {
            abiFilter "armeabi-v7a"
        }
        versionCode = 1
    }
    x86_SDK23 {
        ndk {
            abiFilter "x86"
        }
        sourceSets.debug {
            manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
        }
        sourceSets.release {
            manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
        }
        minSdkVersion 23
        versionCode = 4
    }
    armv7_SDK23 {
        ndk {
            abiFilter "armeabi-v7a"
        }
        sourceSets.debug {
            manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
        }
        sourceSets.release {
            manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
        }
        minSdkVersion 23
        versionCode = 3
    }
    fat {
        sourceSets.debug {
            manifest.srcFile 'config/debug/AndroidManifest_SDK23.xml'
        }
        sourceSets.release {
            manifest.srcFile 'config/release/AndroidManifest_SDK23.xml'
        }
        versionCode = 5
    }
}

applicationVariants.all { variant ->
    def abiVersion = variant.productFlavors.get(0).versionCode
    variant.mergedFlavor.versionCode = defaultConfig.versionCode * 10 + abiVersion
}

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    versionName "4.2.1"
    manifestPlaceholders = [HOCKEYAPP_APP_ID: "3cbcfb69d1ce445ea2d465b3d801c534"]
    externalNativeBuild {
        ndkBuild {
            arguments "NDK_APPLICATION_MK:=jni/Application.mk", "APP_PLATFORM:=android-14"
            abiFilters "armeabi-v7a", "x86"
        }
    }
}
}

    apply plugin: 'com.google.gms.google-services'

Problem is in here

  ConnectionsManager.native_setJava(Build.VERSION.SDK_INT == 14 || Build.VERSION.SDK_INT == 15);

回答1:


I finally solved this myself, after looking into the jni cpp files one by one, I found that the package name still in org.telegram.messenger or org/telegram/messenger - it is not update into my package. I'm not sure if this a bug in the Android Studio, or issue with the source code. After I changed the package the NativeLoader.cpp, SqliteWrapper.cpp, TgNetWrapper.cpp video.c manually and then start build the .so files by following this link https://stackoverflow.com/a/34323758/7531970, don't forget to use ndk 14b and put all details needed. Compile your telegram, and it works!




回答2:


for example you want to change package name to "com.example.messanger".all you have to do is:

1- go to build.gradle change applicationId value to com.example.messanger.

2- go to google-services.json then change package_name value to com.example.messanger.

3- build your project and enjoy :)



来源:https://stackoverflow.com/questions/45890801/telegram-can-not-compile-with-different-package-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!