Android Studio 2.3.3 won't load class file from JAR - java

I've copied a jar file into my project's libs folder. Usually it will show me all of the files contained therein. For this one JAR file, it won't display the class file embedded inside, but does display a manifest file.
Let's say the jar is custom-unity-activity.jar and the directory structure is com\custom\activity\custom-unity-activity.class. As far as Android Studio gets is "com.custom" and then goes no further. The compiler also can't resolve symbols defined in the class file, so it definitely isn't reading it in.
I know this jar file is valid, because it has been used successfully under a different build environment.

It's really hard to import Unity's project into an existing Android Project. The solution is to do it the other way around instead.
Build the Android Studio project as to jar or .arr plugin then place in your Unity project at: <ProjectName>Assets\Plugins\Android.
If you want to load your Android Studio project activity, you must modify the AndroidManifest.xml to let Unity know that then place it at:<ProjectName>Assets\Plugins\Android.
Below is what the XML should look like. It will specify the activity name to load and will also tell Unity to allow you to use input events from your Android Studio project otherwise, Unity will steal those events. The manifest below assumes that the Android Studio activity name is "MainActivity".
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.casualcoder.plugin" android:installLocation="auto">
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:screenOrientation="landscape">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:screenOrientation="landscape">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
</application>
</manifest>

Related

No internet permission but the permission is given, when i intilize the admob banner (it give a red underlying saying i dont have permission)

I get this missing "Missing permissions required by BaseAdView.loadAd: android.permission.INTERNET" when i copy pasted the meta tags that are needed for the google maps sdk, without them it doesn't show the error. What could be the issue and the fix?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="*******">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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/Theme.SmartQ">
<activity
android:name=".mapp"
android:exported="false" />
<activity
android:name=".sdkmaps"
android:exported="false" />
<activity
android:name=".map"
android:exported="false" />
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow the directions here:
https://developers.google.com/maps/documentation/android-sdk/get-api-key
Once you have your API key (it starts with "AIza"), define a new property in your
project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
"YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".Web_view"
android:exported="false" />
<activity
android:name=".Update1"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="*******" />
</application>
</manifest>
picture
The problem is that android is unable to resolve ${MAPS_API_KEY}.
The easiest fix is replacing ${MAPS_API_KEY} with real key directly in manifest, something like:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBdJ88HN7LTGkHHK5whfaVv8a5ozlx2E_k" />
If you anyway want to store your key in .properties file, follow this answer:
How to store maps api key in local.properties and use it in AndroidManifest.xml

"Default activity not found"

I keep getting the "Default activity is not found" error whenever I want to try and run my app. I have tried 'clean project', 'invalidate caches/restart' and restarted my computer.
UPDATE: I tried running different projects, but they all give the same error too. This makes me think there must be something wrong with settings.
It works perfectly for my friend, but I get the error that the "Default activity is not found". If I try to launch a specific activity it also says the activity is not found. This is the code in the androidmanifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ek97.fhict.theapp">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission. ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/loqate_logo"
android:label="#string/app_name"
android:roundIcon="#drawable/loqate_logo"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".bottomnavigationfinal"
android:label="#string/title_activity_bottomnavigationfinal"/>
<activity android:name="Settings" />
<activity
android:name=".Login"
android:label="#string/title_activity_login" />
<activity
android:name=".Registration"
android:exported="true"
android:label="#string/title_activity_registration" />
<activity android:name=".Navigation" />
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<activity
android:name=".GoogleMaps"
android:label="#string/title_activity_google_maps" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
</activity>
<activity android:name=".Profile" />
</application>
</manifest>
If it works for your friend and it is the same code it could be that all you need to do is to refresh the cache of your IDE:
File -> Invalidate Caches / Restart
Try this::
Your manifest is missing default activity
Add to any activity as you consider a default activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
I finally solved it by making sure all implementation versions were the same, there were some in a 28.0.0 version and others in a 26.1.0. version. Now the app works fine on the emulator. Thanks for your suggestions though

Manifest Merger Failed When Trying to Update to Latest FirebaseUI

I am trying to add the latest FirebaseUI dependency to my Android project. I have Facebook login enabled in my project, and when I set up the Facebook login I was required to add my Facebook App ID in the Android manifest. Here is the dependency I added to my android project:
"com.firebaseui:firebase-ui:3.0.0"
After compiling, I received the following error:
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Attribute meta-data#com.facebook.sdk.ApplicationId#value value=() from AndroidManifest.xml:29:13-52
is also present at [com.firebaseui:firebase-ui-auth:3.0.0] AndroidManifest.xml:21:13-60 value=().
Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:27:9-29:55 to override.
I am not sure why I am being prompted to change my Facebook App ID in order to use the latest library. I am updating so that I can take advantage of the new FirebaseUI features and Firebase Cloud Firestore as well.
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="#drawable/xxxxxxx"
android:label="#string/xxxxxxx"
android:theme="#style/AppTheme.NoActionBar"> <!-- ADD THIS LINE -->
<activity
android:name=".SignupActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
tools:replace="android:theme" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.firebase.ui.GoogleClientId"
android:value="#string/google_client_id" />
<meta-data
android:name="com.firebase.ui.TwitterKey"
android:value="#string/twitter_app_key" />
<meta-data
android:name="com.firebase.ui.TwitterSecret"
android:value="#string/twitter_app_secret" />
<activity
android:name=".PollHostActivity"
android:label="#string/title_activity_poll"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".LoadingActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:screenOrientation="portrait" />
<activity
android:name=".CreateActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".NewImageActivity"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity
android:name=".ProfileActivity"
android:label="#string/title_activity_profile"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
Your post says: when I set up the Facebook login I was required to add my Facebook App ID in the Android manifest. That is not the case for firebase-ui-auth:3.1.0 and may not be for 3.0.0 either. With 3.1.0, you define the IDs as string resources, as described here, and FirebaseUI generates the needed manifest entries, which get merged into the main manifest at build time. If you are defining the constants in your manifest manually, that is likely the cause of the merge conflict.
To see the contributors to the merged manifest, open your AndroidManifest.xml file in Android Studio. Click the Merged Manifest tab at the bottom of the window. In the right pane, find and click on firebase-ui-auth:3.0.0 to see the manifest entries that are generated by FirebaseUI for merging into the composite manifest. If you see meta-data entries there that you have manually entered into your manifest, delete your entries to eliminate the merge conflict.
Try following their GitHub readme, located here. I was having the same problem as well and my question got a lot of attention but unluckily none could pin point the problem. The problem lies somewhere in the gradle file where you are writing this "com.firebaseui:firebase-ui:3.0.0".

Cannot read packageName from AndroidManifest.xml

I have errors in my android manifest file:
Error:Cannot read packageName from C:\Users\brandon\AndroidStudioProjects\MineDodge2\app\src\main\AndroidManifest.x‌​ml
Error:The markup in the document preceding the root element must be well-formed.
I tried to look on this website but the answers aren't working for me.
<?xml version="1.0" encoding="utf-8"?>
< manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brandon.MineDodge" >
<application
android:allowBackup="true"
android:icon="#mipmap/redjet"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.brandon.MineDodge.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brandon.MineDodge.Splash" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</application>
</manifest>
If you are using an old version of build.grade file, you should remove this code:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
Then, Build > Clean Project
Note: If you see this code, you are using the old version
I got this error on Unity 2018 and i think it's a bug.
Fix for me:
Add packagename to Android Manifest in Unity project.
In my project path to manifest: Assets/Plugins/Android/AndroidManifest.xml
For example i got error when my Manifest file looks like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
...
</manifest>
It generated by Oculus Gear VR plugin by Unity. But it missed package name and must looks like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest package="YOURPACKAGENAME" xmlns:android="http://schemas.android.com/apk/res/android">
...
</manifest>
Replace YOURPACKAGENAME to Package Name of your project. It should be in Edit -> Project Settings -> Player -> Other Settings -> Identification -> Package Name and should looks like com.YOURORGANIZATION.APPNAME
Some peoples wrote, that manifest must looks like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest package="${applicationId}" xmlns:android="http://schemas.android.com/apk/res/android">
...
</manifest>
And they wrote that Unity will replace ${applicationId} on package name when build android application, but in my Unity 2018.1.6f1 it doesn't work and i think it's a bug too.
The error is really simple, and I'm rather dissapointed with the stack community to not have found it till now.
< manifest ...
should become
<manifest...
Basically, remove that extra space. That's what's causing the following error :
Error:The markup in the document preceding the root element must be well-formed.
Also, the intent-filter used for the MainActivity, must similarly be used for the second activity.
Hope this issue is resolved.
My problem was that I was trying to convert an old Eclipse project to Android Studio project where the manifest file is expected to be on a different location (along with other files). Specifically project\app\src\main
In response to Eldar Kurbanov who had this error in Unity & anyone else who finds this question after having the error when building with gradle in Unity.
This is not a Unity 2018 'bug' nor is it caused by something being missing from the Manifest pre-build. It's actually caused by the mainTemplate.gradle file missing the line:
applicationId '**APPLICATION**'
Inside the defaultConfig {} block of the android {} section. This will ensure the generated manifest has the package name inserted into it.
Yes manually inserting the package name into the main manifest will work, but it's much better to just use Unity's project settings to set the package name rather than hard-coding it.
If anyone else finds this question and they're using Unity then here's an example mainTemplate.gradle you can use for referencing: https://pastebin.com/hPs0uvkZ
why you mentioned <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> twice? Remove any one from those two.
Your second <action android:name="android.intent.action.MAIN" /> and
<category android:name="android.intent.category.LAUNCHER" /> are not allowed here.
I think
`
< manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brandon.MineDodge" >
<application
android:allowBackup="true"
android:icon="#mipmap/redjet"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.brandon.MineDodge.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brandon.MineDodge.Splash" />
</application>
`
That will be OK.
I had this in a multi-subproject project, caused by the subproject not matching the configure( clause in the top-level build.gradle.
Specifically I had
configure(subprojects.findAll { it.name.startsWith("pachymeninx") }) {
which did not match my new subproject called pachymen. But the Gradle build process issued no warning (that I saw) and instead gave "Cannot read packageName from AndroidManifest.xml" error for the pachymen subproject.
Thats simply because you either copied an already existing project and its files into your newly created project. Thereby causing Manifest conflict. Because the manifest copied belongs to the other project and its paths.
you need to recreated a manifest file in your own project file path and possibly manually copy the other project's manifest code into your newly created manifest file.
Check if your src file is named with some different name.....if thats the case then you might end up with this error....rename it to "src
check your manifest file should be at-> \android\app\src\main\AndroidManifest.xml
otherwise android can't find the package name in Manifest file from a specific location
In my case, the module level android manifest file was in the wrong location. It was inside src/java/ whereas it is supposed to be in src/
try this ,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brandon.MineDodge">
<application
android:icon="#drawable/launchicon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseThemeTP">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Splash"
android:screenOrientation="portrait"
android:theme="#style/AppBaseThemeTP" >
</activity>
</application>
</manifest>
The android:name="com.example.brandon.MineDodge.MainActivity" should be under <application>, not under <activity>.
<activity
android:name="com.example.brandon.MineDodge.Splash" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</application>
change it to--
<activity
android:name="com.example.brandon.MineDodge.Splash" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</application>

Android Multi Window doesn't work when android:screenOrientation="portrait"

as the title says, when the next line of code
android:screenOrientation="portrait"
is entered in my Manifest file then when I start my app and, for example, dragging the gallery app to it then its not activating the multi window feature which splits the screen... but just replace my app with the gallery app, meaning the gallery app takes all the screen instead of taking only half of it.
If I first open the gallery app and then dragging my app then its working fine.
Also if I remove the above line of code then its working fine.
This is my Manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.samsunmultiwindowstest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.samsunmultiwindowstest.MainActivity"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER"/>
</intent-filter>
</activity>
<uses-library android:required="false" android:name="com.sec.android.app.multiwindow"> </uses-library>
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632.0dip" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598.0dip" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632.0dip" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598.0dip" />
</application>
how can I force portrait mode and get the multi window feature?
Thank you and sorry for my English.
Check out this Link Screen Orientation. It will help you understand different kinds of screen orientation. Also check this and this. will help you to enable multi window feature
I simply took out the size settings to solve my multiWindow issues.
IE: Remove these lines altogether.
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632.0dip" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598.0dip" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632.0dip" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598.0dip" />

Categories

Resources