Importing Telegram API from GitHub repository to Android Studio - java

As you know Telegram API is open on GitHub. I tried to import it on my Android Studio. My android studio is up to date and also SDK is updated till the date. I have generated signed APK and tried to run project and got following errors. I have chosen x86 based to compile and tried to run it.
Screenshot.
http://img.prntscr.com/img?url=http://i.imgur.com/b0HqgmO.png
05/23 21:39:23: Launching TMessagesProj
The currently selected variant "arm-debug" uses split APKs, but none of the 1 split apks are compatible with the current device with density "560" and ABIs "x86".
Error while Installing APK
Any help would be appreciated.
Thank You!

The following image describes the solution.

in the defaultConfig (gradle Build file) add this at the end of android {} check for your architectures
android {
...
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk true
}
}
}

Related

I have tried to generate a signed version of my app and I got those errors. What could be the problem in my code? [duplicate]

I don't know why but it's impossible to launch my app on my mobile this morning. I get this error message:
Cannot fit requested classes in a single dex file. Try supplying a
main-dex list.
# methods: 68061 > 65536 Message{kind=ERROR, text=Cannot fit requested classes in a single dex file. Try supplying a main-dex list.
# methods: 68061 > 65536, sources=[Unknown source file], tool
I'm really new to Android and I don't understand the problem and what I need to do? And why I get this problem now and not before?
In root build.gradle file do something like:
dependencies {
// ...
implementation 'androidx.multidex:multidex:2.0.1'
}
android {
defaultConfig {
// ...
multiDexEnabled true
}
}
More details here: Error:Cannot fit requested classes in a single dex file.Try supplying a main-dex list. # methods: 72477 > 65536
Running RN 0.62 and this worked for me with successful build.
Update build.gradle
classpath('com.android.support:multidex:1.0.3')
Update defaultConfig
multiDexEnabled true
After those 2 changes, restart the gradle build again.
Multidex is not always the solution to the problem, is true that it will generate more dex files to fit your method count, but be sure to not import more methods that you need because this in long term will make your builds slower than before.
For example, if you just need to use the location library from play services, you have two options
First one is implementing the whole play-services libraries that will come with location
implementation 'com.google.android.gms:play-services:11.8.0'
These whole libraries could have more than 40.000+ methods (is only an estimative, I don't really know the total count), being close to reaching the 65536 limit methods.
Instead you should be targeting only the libraries you will use instead of the whole bundle of libraries
in this case
implementation 'com.google.android.gms:play-services-location:11.8.0'
could have just 50 - 100 methods to work with, which will be better at build time than loading a whole bunch of methods from the whole library package that you won't ever use.
this is just a tip to avoid getting
Cannot fit requested classes in a single dex file.
For minSdkVersion above android 5.0 API 20 +
Android 5.0 and higher uses a runtime called ART which natively
supports loading multiple dex files from application APK files. ART
performs pre-compilation at application install time which scans for
classes(..N).dex files and compiles them into a single .oat file for
execution by the Android device. For more information on the Android
5.0 runtime, see Introducing ART.
If you are targeting lower devices (Android 4.1 API 16) or before Android 5 (API 20)
Versions of the platform prior to Android 5.0 use the Dalvik runtime
for executing app code. By default, Dalvik limits apps to a single
classes.dex bytecode file per APK. In order to get around this
limitation, you can use the multidex support library, which becomes
part of the primary DEX file of your app and then manages access to
the additional DEX files and the code they contain.
You will need to use multidex in this last case
In build.gradle(app) file:
Add the following in the dependencies:
implementation 'com.android.support:multidex:1.0.3'
And add the following in the defaultConfig,
multiDexEnabled true
Hope you will find the solution.
Update 2021 Android-X and Android Studio 4.XX:
Adding multiDexEnabled in the default config of your app-level Build.Gradle is enough
multiDexEnabled true
See image for reference
Recommended solution for android x
why the error
When your app and the libraries it references exceed 65,536 methods, you encounter a build error that indicates your app has reached the limit of the Android build architecture more information here
solution
just add the multi dex support library to your dependencies in the buid.gradle (Module: app) file
dependencies {
def multidex_version = "2.0.1"
implementation 'androidx.multidex:multidex:$multidex_version'
}
You can fix this problem by following these steps.
Step 1: Migrate to AndroidX
Refactor > Migrate to AndroidX
Step 2: Add this dependency in build.gradle file:
implementation 'androidx.multidex:multidex:2.0.1'
Step 3: In build.gradle's defaultConfig section add:
multiDexEnabled true
This error is comes when you use deprecated npm as well as correct npm for same purpose

Source code does not match the bytecode for Android's View.java

I am attempting to debug my Android app. When the debugger gets to the View.java file, I receive the message, "Source code does not match the bytecode". I can see that the debugger is in the wrong part of the file. Does anyone know how to fix this?
I am debugging on an Android 10 (API 29) device. In the Android Studio Preferences -> Appearance & Behavior -> System Settings -> Android SDK, I've made sure everything is up to date. I've also cleaned and rebuilt multiple times, removed caches, restarted Android Studio and the device, uninstalled/re-installed, updated Android Studio to 4.0.1. In the Module Settings, the "Compile Sdk Version" is 29, and the Target SDK Version and Min SDK Version to 29. Nothing helps or has any effect. Many of these steps were suggested in similar posts.
The View.java file it tries to open is at: ~/Library/Android/sdk/sources/android-29/android/view/View.java. This should be the correct file, yet the debugger is in the wrong part of the file while I get the error message.
Putting on my black hat, let's assume that my laptop's View.java is correct for that API level: could my phone be running non-standard code, and is there any way to detect that or rule it out?
I think I figured out what was happening and I have a solution for this problem when it happens with Android SDK files. Frighteningly, the Android SDK Platform gets updated to Revision 5, but the source package is not updated. It is still on Revision 1! Why this happened, I cannot explain: a reasonable person would expect both to be in sync. This screenshot shows the source code does not match the binary that Android Studio downloaded:
The only way around this is to manually download the files you need and patch them manually in your SDK source directory. It's ugly, it's unnecessary, but if you really want to step through a specific SDK file you have to do it.
Find out what Android build you have. On your device, go to "Settings" -> "About phone" -> "Android version", and note down your "Build number" value. Mine is QQ3A.200805.001.
Find out the Tag corresponding to your Build number using this page: https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds. For my build number, the tag is: android-10.0.0_r41
Download the AOSP source for this tag. This takes a long time if you are doing this for the first time. See https://stackoverflow.com/a/14353644/259718 for an example on how to do that.
Copy the files to overwrite some of the source directories: cp -pr ~/android_src/frameworks/base/core/java/android/* ~/Library/Android/sdk/sources/android-29/android/ (use the correct location for your environment, here I am compiling with android-29)
While not all of the directories in the android sources folder are overwritten, the core android files are overwritten. These comprise the majority of the source material. If you need other directories (e.g. "filterpacks"), you'll have to find that in the other AOSP directories (e.g. frameworks/base/media for "filterpacks").
Here are the steps I followed to get just one individual file:
Find the file you need on https://android.googlesource.com. Using google.com, I found it at: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/View.java
Determine the Android repo your file lives in. Looking at the previous URL, I can deduce it's at: https://android.googlesource.com/platform/frameworks/base/
Grab that repo using your tag. Or grab that tag's most recent revision of that individual file on-line, e.g.: https://android.googlesource.com/platform/frameworks/base/+log/refs/tags/android-10.0.0_r41/core/java/android/view/View.java, revision 18c0fbf.
To download the individual file, add "?format=text" to the URL to get the base64 encoded version. Then decode it: cat file | base64 --decode.
Now you have the file. Go to your SDK directory that contains the errant file: cd ~/Library/Android/sdk/sources/android-29/android/view/
Backup the old file (cp -pr View.java View.java.orig) if you want (you can always re-install the SDK source files if you mess up). Copy in your new file into the same location.
Now, your debugger will use the correct file! You will have to do this for each file that your debugger complains about.
I hope this helps someone else in the future. I spent a lot of time figuring this out and I sincerely hope someone else won't have to waste that time. Google needs to keep the source packages consistent with the release packages. Looking at all the past SDK releases, none of the source packages appear to be in sync with the latest release version. Maybe another ugly way to debug SDK files is to use a Revision #1 SDK release version that matches the Revision #1 source package.
Unfortunately curious_george's solution only works if the device has a version of Android built directly from the published Google sources. Device manufacturers are not obliged to do that, and the Apache Licence used by Google, unlike the GPL, does not oblige publishers of derivative works to give access to their sources.
My device is a Samsung Galaxy S21, and the build number of the currently installed Android is
SP1A.210812.016.G998BXXU4BULF, which is of course not listed in https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds.
The versions of the sources tagged 210812.016 listed there are
210812.016.A1 android-12.0.0_r3 Tue Aug 24 18:43:39 2021
210812.016.A2 android-12.0.0_r25 Tue Aug 24 18:43:39 2021
210812.016.B1 android-12.0.0_r30 Fri Dec 24 23:08:44 2021
210812.016.C1 android-12.0.0_r31 Sat Dec 25 00:36:35 2021
They all appear to have the same version of View.Java, and Android Studio says that it isn't the version in my device. Even a comment change can confuse the debugger since it looks for the code at a particular line number.
At the moment I also can't debug using the emulator, which would presumably have a genuine Google release of Android, since the latest release of Android Studio (Android Studio BumbleBee | 2021.1.1 Patch 2, Build #AI-211.7628.21.2111.8193401, built on February 17,2022) seems to have broken it. The emulator either locks up its UI or crashes when started, and the debugger can't connect to it.
So there seems currently to be no way of solving the originally posted problem.
HELP!!

GStreamer Android Tutorial Build Failed

I'm running into number of problems while trying to run GStreamer Android Tutorials on Windows. I'am new to Android NDK so this could be a really simple issue but I couldn't figure out how to solve it.
These are the build error messages when I try to build the project
Build command failed.
Error while executing process
D:\gstreamer\android-ndk-r19b-windows-x86_64\android-ndk-r19b\ndk-build.cmd
with arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\jni\Android.mk
NDK_APPLICATION_MK=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\jni\Application.mk
APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0
APP_PLATFORM=android-16
NDK_OUT=C:/xxx/xxx/gst-docs-master/examples/tutorials/android/android-tutorial-1/build/intermediates/ndkBuild/release/obj
NDK_LIBS_OUT=C:\xxx\xxx\gst-docs-master\examples\tutorials\android\android-tutorial-1\build\intermediates\ndkBuild\release\lib
NDK_APPLICATION_MK=jni/Application.mk GSTREAMER_JAVA_SRC_DIR=src
GSTREAMER_ROOT_ANDROID=D:/gstreamer/gstreamer-1.0-android-universal-1.15.1
GSTREAMER_ASSETS_DIR=src/assets APP_SHORT_COMMANDS=false
LOCAL_SHORT_COMMANDS=false -B -n}
process_begin: CreateProcess(NULL, "", ...) failed.
*** Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File
When I clicked the "Open File" it has sent me to gstreamer-1.0.mk file and the lines below.
ifdef SYSROOT
SYSROOT_GST_INC := $(SYSROOT)
SYSROOT_GST_LINK := $(SYSROOT)
else
ifdef SYSROOT_INC
$(call assert-defined, SYSROOT_LINK)
ifdef SYSROOT_LINK
SYSROOT_GST_INC := $(SYSROOT_INC)
SYSROOT_GST_LINK := $(SYSROOT_LINK)
endif
else
SYSROOT_GST_INC := $(NDK_PLATFORMS_ROOT)/$(TARGET_PLATFORM)/arch-$(TARGET_ARCH)
SYSROOT_GST_LINK := $(SYSROOT_GST_INC)
endif endif
I think the problem is about SYS_ROOT as mentioned in the error message but I don't know what "SYS_ROOT" means or "NDK_PROJECT_PATH" is.
I have added gstAndroidRoot to gradle.properties so while building this won't be a problem.
For Windows 10, Android Studio 3.5. This worked for me.
Download the entire gstreamer android studio tutorial directory from here.
Open Android Studio -> Open an existing Android Studio Project
Open the entire android tutorial directory examples/tutorials/android as a project
Once the project is open change the view on the left side of the screen to Project
Right click near local.properties. Right click -> file -> New -> File
Create a new file called gradle.properties
In the new gradle.properties file copy and paste the below code.
# gstAndroidRoot can be set to point to the unpacked GStreamer android top-level directory
# containing each architecture in subdirectories, or else set the GSTREAMER_ROOT_ANDROID
# environment variable to that location
gstAndroidRoot=/gstreamer_android_binaries
Note: Change the gstAndroidRoot variable to your file path where you downloaded the gstreamer binaries and unzipped them. Gstreamer can be downloaded from here for Android.
Now we need to set up NDK directory. Make sure you download and have NDK enabled under SDK tools.
This will download the latest NDK version. However gstreamer currently will not build with the latest NDK. We need to download NDK Revision 18b from here. If you do not use NDK version 18 you will likely get an error Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File
Unzip the downloaded NDK 18b directory.
Take the unzipped android-ndk-r18b directory and move it to where the ndk folder is under AppData\Local\Android\Sdk\ndk
You should now have two folders within Android\Sdk\ndk. 20.0.5594570 (or latest version) and android-ndk-r18b
In android studio go to File -> project Structure
Under Android NDK location point to the NDK 18 directory. Example: C:\Users\AppData\Local\Android\Sdk\ndk\android-ndk-r18b
Connect a phone with USB debugging and run!
If you get an error on the phone stating it is for an older version of android. Go back to Android Studio and switch to Android View on the left side of the screen. Under Gradle Scripts select the build.gradle for the appropriate tutorial. Change the compileSdkVersion 29, minSDKVersion 15, and targetSDKVersion 29.

Android studio ; jni.h not found

I'm trying to build a GStreamer app using Android Studio on windows using the tutorials on their website, but, as already mentioned in other questions, the tutorials are not up-to-date nor seems to work on Android Studio. I've followed the tutorial proposed by Eduardo Fernando at :
Gstreamer examples in Android Studio, but it won't build since I can't manage to fix the issue of the jni.h file not found.
> Build command failed.
Error while executing process
C:\Users\spomerleau\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with
arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=C:\Users\spomerleau\Desktop\Android_GSTreamer\Premade_Test_tut5\android-tutorial-5\app\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\Users\spomerleau\Desktop\Android_GSTreamer\Premade_Test_tut5\android-tutorial-5\app\src\main\jni\Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=C:/Users/spomerleau/Desktop/Android_GSTreamer/Premade_Test_tut5/android-tutorial-5/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\spomerleau\Desktop\Android_GSTreamer\Premade_Test_tut5\android-tutorial-5\app\build\intermediates\ndkBuild\debug\lib C:/Users/spomerleau/Desktop/Android_GSTreamer/Premade_Test_tut5/android-tutorial-5/app/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libtutorial-5.so}
GStreamer : [GEN] => gst-build-arm64-v8a/gstreamer_android.c
GStreamer : [COMPILE] => gst-build-arm64-v8a/gstreamer_android.c
gst-build-arm64-v8a/gstreamer_android.c:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
^~~~~~~
1 error generated.
make: *** [gst-build-arm64-v8a/gstreamer_android.o] Error 1
I executed the javah command, but the generated .h cannot find the #include either.
I tried the ndk-build command, but it will stop saying the jni.h file is missing.
Any advices on how I could link the jni.h file to the project?
This is potentially a problem with the r16 changes in the Android NDK which are fixed upstream by the following commit
The problem is that the NDK moved the header files around into a unified structure and thus broke any user expecting headers in the old locations.
This is due to Android Studio updating/installing to NDK_r16, which deprecated GCC support. Try reverting to NDK_r15c.
Download r15c from https://developer.android.com/ndk/downloads/older_releases.html, then point the app's NDK Location to the extracted folder.
jni.h is a header file which is already present in the android ndk package. If it is not present you can either reinstall the package or you can search over the web for the source file which you can get very easily and place that file into the location your compiler is expecting it to be

ndk.dir error in Android Studio

I was trying to use opencv library, so I imported one of its projects in Android Studio and when I tried to run it I got this error:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
NDK not configured.
Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
(On Windows, make sure you escape backslashes, e.g. C:\ndk rather than C:\ndk)
So I downloaded the ndk and I addes this line to the local.properties file where it became:
sdk.dir=C\:\\Users\\skoon\\AppData\\Local\\Android\\sdk
ndk.dir=C\:\\Users\\skoon\\AppData\\Roaming\\IDM\\android-ndk-r10d
but I still got this error which I didn't understand:
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-14 NDK_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\lib APP_ABI=all
Error Code:
2
Output:
make.exe: *** No rule to make target 'C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni', needed by `C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.o'. Stop.
I didn't change anything in the code, so what should I do? do I need to change or add any variables to point to the ndk?
P.S. This is my first time trying to build Android application so I don't have any experience.
Thank you in advance.
UPDATE:
To import the project I just used import project from file, then I synced the gardle, and run the project.
the package that I downloaded from opencv was the Android one, and I tried to use the face detection sample.
when I run it I got the error above.
You need to setup OpenCV librairies for your project. You can follow the instruction here.
OpenCV sample projects haven't support gradle officially. I think it will be easier if you start a new project and configure it to work as in examples.
I have implemented a tutorial project using Android Studio + NDK + OpenCV. You may have a look. https://github.com/quanhua92/NDK_OpenCV_AndroidStudio
Install NDK in your SDK manager, if you already installed open app's "build.gradle" replace these lines
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jni/'] } }
to
sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs' // mention your JNI lib path(where ".so" files contains)
jni.srcDirs = [] //disable automatic ndk-build call
}
I'm tried to configure OpenCV and its fixed

Categories