I was trying to add Google Maps service in emulator in Android Studio for Mac.
I used this to add google play services in my emulator and now I am getting this error.
I also added Google play jar in "libs"
Build error
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/21.0.0/dx --dex --num-threads=4 --output /Users/BrijD/Desktop/Final_maps/app/build/intermediates/dex/debug /Users/BrijD/Desktop/Final_maps/app/build/intermediates/classes/debug /Users/BrijD/Desktop/Final_maps/app/build/intermediates/dependency-cache/debug /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-0fd5fdfe526893278be8c195ce134eaf1d9f1e86.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-1c1ab6ce82c35aba8a1d88f2624cf1338444a247.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-3fa4a9ac8fa2216bad3a7f16c9a774b0dc355d43.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/classes-8f6dc1447c1249308d36a8f93d1adf33837f8664.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/internal_impl-21.0.0-fd4beb3682904051af27f723f6ba9423e4f00b8a.jar /Users/BrijD/Desktop/Final_maps/app/build/intermediates/pre-dexed/debug/support-annotations-21.0.0-ee576f91b45a6538d4156fc6e674b6f65034f74e.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/actions/ReserveIntents;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
AndroidMainefest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dormroomdevelopers.final_maps" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MapsActivity">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="*****************************"/>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21"
defaultConfig {
applicationId "dormroomdevelopers.final_maps"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.android.gms:play-services-maps:6.5.+'
}
proguard-rules.pro
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
This error in general means that you've tried to link in the same class to your project more than once, which isn't allowed. The offending class is com/google/android/gms/actions/ReserveIntents, which is in the Google Play Services library.
The problem is in your dependencies:
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.android.gms:play-services-maps:6.5.+'
These are redundant. The play-services:6.5.87 includes everything, and if you have that, you don't need the play-services-maps:6.5.+ dependency. The reason you might want the latter one is if your project gets too big and you need to pare down to a smaller, more granular Play Services where you only include what you need.
To make life easier, I'd recommend going with the first one, and if you run into compile problems (such as the most classic one, Unable to execute dex: method ID not in [0, 0xffff]: 65536, though it takes different forms), then you can go to the latter format.
There's more documentation on how to use the big library and the smaller libraries at http://developer.android.com/google/play-services/setup.html and http://developer.android.com/google/play-services/setup.html#split
It seems you have a jar file or a lib appearing multiple times. So, remove the .jar file from the lib folder Build> Rebuild Must work.
Related
Does Xamarin support multiple levels of project reference nesting, where the referenced project includes Android components intended for the AndroidManifest.xml?
For example: AndoidXamarin App > ClassLibrary1 > (which declares a Service) ClassLibrary2 (which also declares a Service):
// ClassLibrary1:
// Referenced by the XamarinApp
// References ClassLibrary2
namespace ClassLibrary1
{
[Service(Exported = true, Name = "com.company.test." + nameof(ClassLib1Service))]
public class ClassLib1Service : Service
{
public override IBinder OnBind(Intent intent) => throw new NotImplementedException();
}
}
// ClassLibrary2
// Referenced only by ClassLibrary1
namespace ClassLibrary2
{
[Service(Exported = true, Name = "com.company.test." + nameof(ClassLib2Service))]
public class ClassLib2Service : Service
{
public override IBinder OnBind(Intent intent) => throw new NotImplementedException();
}
}
// The generated `AndroidManifest.xml` only includes the Service defined in ClassLibrary1.
<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/AppTheme" android:name="android.app.Application">
<activity android:label="#string/app_name" android:theme="#style/AppTheme" android:name="crc64a7a6b04b89628087.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:exported="true" android:name="com.company.test.ClassLib1Service" />
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.company.test.mono.MonoRuntimeProvider.__mono_init__" />
</application>
I am receiving this error when trying to launch a Xamarin forms application on Android from a text message URL. I have been following the steps noted in THIS article.
Here the application node in my AppManifest.xml
<application android:label="Label A">
<activity android:icon="#drawable/Icon" android:label="LabelB" android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="superduperapp" />
</intent-filter>
</activity>
</application>
According to the article I need to do something with intent objects to get the OnCreate override to fire but I think I am not matching something up right with my manifest and the naming convention for a class I created below.
[Activity(Label = "urlentryclass")]
public class OpenFromURI : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Intent outsideIntent = Intent;
var x = Intent.Data.EncodedAuthority;
}
}
So, with the above code added to my xamarin solution I also have a webpage with the code below..
and when i click the link above from my mobile browser it touches the mobile app because I get the error below
MyApp.Mobile.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "MyApp.Mobile.Droid.MainActivity" on path: DexPathList[[zip file "/data/app/MyApp.Mobile.Droid-1/base.apk"],nativeLibraryDirectories=[/data/app/MyApp.Mobile.Droid-1/lib/arm64, /data/app/MyApp.Mobile.Droid-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]] occurred
MyApp.Mobile.Droid.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "MyApp.Mobile.Droid.MainActivity"
Xamarin.Android, by default, generates the Java wrappers using MD5-based class names to avoid Java class name clashing, such as:
md579731053346ff64fcf21847b09163ce1.MainActivity
You have hard-coded a android:name=".MainActivity" in your manifest but the generated class will be MD5-based by default.
Open up your MainActivity and within the ActivityAttribute on your MainActvity class, add a fully qualified name within a Name parameter of that attribute, this will force the Xamarin.Android build process to use a Java-class name of your choosing vs. the MD5-based one and thus it will match your manifest entry.
Example:
[Activity(Name = "MyApp.Mobile.Droid.MainActivity", Label = "MySuperDuperApp", MainLauncher = true, Icon = "#mipmap/icon")]
public class MainActivity : Activity
{
~~~
I'm Trying to make a google translation app using Google's Cloud Translation API. When i'm trying to compile compile 'com.google.cloud:google-cloud-translate:1.14.0' errors as Duplicate files copied in APK project.properties
My android code is as below (No problem in java code)
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.Translate.TranslateOption;
import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
public class QuickstartSample {
public static void main(String... args) throws Exception {
Translate translate = TranslateOptions.getDefaultInstance().getService();
String text = "Hello, world!";
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("en"),
TranslateOption.targetLanguage("ru"));
System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", translation.getTranslatedText());
}
}
My build.gradle is as below (problem arrises due to below given compile statement)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.googletranslation"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
**compile 'com.google.cloud:google-cloud-translate:1.14.0'**
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
testCompile 'junit:junit:4.12'
}
Im getting erros as Below:
Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (3.0.0) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
Warning:WARNING: Dependency org.json:json:20160810 is ignored for release as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
I have tried all methods in below link but there is no effect. still errors are increasing
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'
One have to include these:
android {
packagingOptions {
exclude 'project.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}}
}
Hoping someone can provide me with some guidance on an issue I'm facing using MEF with my VS2015 extension. I'm attempting to extend the IntelliSense capabilities of VS and followed this tutorial as a basis: https://msdn.microsoft.com/en-us/library/ee372314.aspx
Here is my ICompletionSourceProvider:
[Export(typeof(ICompletionSourceProvider))]
[Name("Test Statement Completion Provider")]
[Order(Before = "default")]
[ContentType("text")]
internal class MyCompletionSourceProvider : ICompletionSourceProvider
{
[Import]
internal ITextStructureNavigatorSelectorService NavigatorService { get; set; }
[Import]
internal IServiceProvider ServiceProvider { get; set; }
public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
{
return new MyCompletionSource(this, textBuffer);
}
}
The strange thing here is that this works fine on my machine (where this code was initially developed on), but fails to work on every other machine I've tried (both in Debug and Release). Breakpoints placed within TryCreateCompletionSource are never hit. I suspected this MEF component was never being exported, so I downloaded the mefx tool as recommend on MSDN and executed it on my generated DLL and received the following:
[Primary Rejection]
[Export] MyVSIX.Source.MyCompletionSourceProvider (ContractName="Microsoft.VisualStudio.Language.Intellisense.ICompletionSourceProvider")
[Import] MyVSIX.Source.MyCompletionSourceProvider.NavigatorService (ContractName="Microsoft.VisualStudio.Text.Operations.ITextStructureNavigatorSelectorService")
[Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No exports were found that match the constraint:
ContractName Microsoft.VisualStudio.Text.Operations.ITextStructureNavigatorSelectorService
RequiredTypeIdentity Microsoft.VisualStudio.Text.Operations.ITextStructureNavigatorSelectorService
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at Microsoft.ComponentModel.Composition.Diagnostics.CompositionInfo.AnalyzeImportDefinition(ExportProvider host, IEnumerable`1 availableParts, ImportDefinition id)
[Import] MyVSIX.Source.MyCompletionSourceProvider.ServiceProvider (ContractName="System.IServiceProvider")
[Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No exports were found that match the constraint:
ContractName System.IServiceProvider
RequiredTypeIdentity System.IServiceProvider
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at Microsoft.ComponentModel.Composition.Diagnostics.CompositionInfo.AnalyzeImportDefinition(ExportProvider host, IEnumerable`1 availableParts, ImportDefinition id)
If I remove the [Import] statements these are all resolved and things begin working again. From the tutorial though, this seems as though it should just work. This also doesn't explain why it works 100% of the time on my machine and never works on any other machines.
This is my .vsixmanifest file:
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="MyVSIX.Company.39048217-955a-4402-84e9-8a24f0730e72" Version="1.0" Language="en-US" Publisher="MyVSIX" />
<DisplayName>MyVSIX</DisplayName>
<Description xml:space="preserve"></Description>
<Icon>Resources\MyVSIX.ico</Icon>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[14.0]" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
<Dependency Id="Microsoft.VisualStudio.MPF.14.0" DisplayName="Visual Studio MPF 14.0" d:Source="Installed" Version="[14.0]" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
<Asset Type="Microsoft.VisualStudio.ItemTemplate" Path="Output\ItemTemplates" />
<Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path="Output\ProjectTemplates" />
</Assets>
</PackageManifest>
Figured out why it wasn't working on other machines, but I still cannot understand why it was ever working on my machine. I changed this:
[Import]
internal IServiceProvider ServiceProvider { get; set; }
to this:
[Import(typeof(SVsServiceProvider)]
internal IServiceProvider ServiceProvider { get; set; }
Hope this helps someone in the future - I spent 2 days figuring this out!
Dear talented programmers!
I have been working with OSGI framework and was trying to applied Declarative Service in my program, but it printed nothing on the screen.
My program is simple, just have one interface, one class implements it and one class consume the interface as the client.
- The Interface is:
package test.osdids.date;
public interface IDateService {
String getDate();
}
- The class implements Interface as the Service is:
package test.osdids.date.service;
import java.util.Calendar;
import test.osdids.date.IDateService;
public class DateService implements IDateService {
#Override
public String getDate() {
String date = Calendar.getInstance().getTime().toString();
return date;
}
}
The XML to registered the service is:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
name="test.osdids.date.service">
<implementation class="test.osdids.date.service.DateService" />
<service>
<provide interface="test.osdids.date.IDateService" />
</service>
</scr:component>
The Manifest file of the service is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TESTOSDIDSDATESERVICE
Bundle-SymbolicName: TESTOSDIDSDATESERVICE
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Service-Component: OSGI-INF/DateBridge.xml
Export-Package: test.osdids.date
Bundle-ActivationPolicy: lazy
- And now, this is the class which will consume the service as the client and prints out the result ( This class was located in other plug-in project, different from the former plug-in project which stored the interface and the implementation class above):
package test.osdids.date.consumer;
import test.osdids.date.IDateService;
public class DateConsumer {
private IDateService dateService;
public synchronized void setService(IDateService dateService) {
this.dateService = dateService;
System.out
.println("The Date Service has been registered successfully!");
System.out.println("The current time is: " + dateService.getDate());
}
public synchronized void unsetService(IDateService dateService) {
System.out
.println("The Date Service has been unregistered successfully!");
}
public void activate() {
System.out.println("Test again...");
System.out.println("The current time is: " + dateService.getDate());
}
public void deactivate() {
System.out.println("Stop the service!");
}
}
- This is the XML file to consume and bind the service of consumer class:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
name="test.osdids.date.consumer" activate="activate"
deactivate="deactivate" enabled="true" immediate="true">
<implementation class="test.osdids.date.consumer.DateConsumer" />
<reference bind="setService" cardinality="1..1"
interface="test.osdids.date.IDateService" name="IDateService" policy="static"
unbind="unsetService" />
</scr:component>
- This is the manifest file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TESTOSDIDSDATECONSUMER
Bundle-SymbolicName: TESTOSDIDSDATECONSUMER
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: TESTOSDIDSDATESERVICE;bundle-version="1.0.0"
Service-Component: OSGI-INF/DateBridgeConsumer.xml
Import-Package: test.osdids.date
Bundle-ActivationPolicy: lazy
- And here is the result on the screen:
osgi>
(Nothing happened)
But when I use jUnit test to test the method activate() in class DateConsumer, it worked. However, when I tried to run the plug-in project by OSGI framework, nothing happened.
I hope that someone who knows this problem and help me.
Thanks a lot in advance!
I got the answer, just launch the bundle consumer by Eclipse framework (product), not by OSGI framework, then the bundles will work smoothly